Set variable in LuaFunction without using globals #102

Closed
opened 2022-05-19 21:59:11 +00:00 by orange451 · 1 comment
orange451 commented 2022-05-19 21:59:11 +00:00 (Migrated from github.com)

I created a stackoverflow question here:
https://stackoverflow.com/questions/72307489/luaj-set-variable-in-luafunction-without-using-globals

I have a LuaFunction where in I will call the invoke() method and pass in some var-args. I wish to pass some data to this LuaFunction such that it can be referenced by the lua code as if it was a built-in variable.

For example, I want to have a variable named "script". When a script class executes its lua code, and it references the "script" value, I want it to represent that script object, but only for that lua code--I want no other lua code to be able to see this variable.

Currently, I am using Globals via:

globals.set("script", reference);
function.invoke(args);

Lua code:

print(script)
> "Script"

While this does work, I can reference "script" in my lua code, this also sets _G.script, which I do not like.

Does anyone have any ideas for this situation?

I created a stackoverflow question here: https://stackoverflow.com/questions/72307489/luaj-set-variable-in-luafunction-without-using-globals -- I have a LuaFunction where in I will call the invoke() method and pass in some var-args. I wish to pass some data to this LuaFunction such that it can be referenced by the lua code as if it was a built-in variable. For example, I want to have a variable named "script". When a script class executes its lua code, and it references the "script" value, I want it to represent that script object, but only for that lua code--I want no other lua code to be able to see this variable. Currently, I am using Globals via: ``` globals.set("script", reference); function.invoke(args); ``` Lua code: ``` print(script) > "Script" ``` While this does work, I can reference "script" in my lua code, this also sets _G.script, which I do not like. Does anyone have any ideas for this situation?
orange451 commented 2022-06-21 13:33:20 +00:00 (Migrated from github.com)

Still unable to resolve this.

Still unable to resolve this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#102