Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0

Loading Strings


Hello! Been coding a bit with Lua for quite some time and am currently creating a program that allows for customization if the user sees fit with the use of changeable variables and the use of the "load()" method. I've used load() in the past however it seems that when using load() to define a variable as a component, the function that is created from the load() seems to not recognize the "component" variable that I declared earlier within the code.

Here's the snippet from my program:

local objTesseract  = "tile_thermalexpansion_ender_tesseract_name"
local objBuffer     = "bc_pipe"

local component = require("component")

if component.isAvailable(objTesseract) and component.isAvailable(objBuffer) then
    load("local t = component."..objTesseract.." local b = component."..objBuffer)()

Error produced:

Is there something I can do to achieve the product that I want? Perhaps there is a thing that I am missing or doing wrong? Maybe this isn't even possible! (I highly doubt this, however, if this is the case, ill have to sacrifice the customization of the program) Regardless, please let me know, and thank you in advance for all of your help!

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

The load function (assuming lua 5.2) will take and environment argument as a table. Try like so..

local com = require 'component' -- local var 'com' in this env
 -- expose 'com' from this env as 'component' in the loaded 'fn' env
local fn = load('return component.list(...)', '=fn', 't', { component = com })

print(fn('gpu')) -- should basically be `component.list('gpu')`

See lua 5.2 'load' function

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.