So for example, I have this code.
[lua]
--scope 2
for k,v in pairs(tbl) do
--scope 1
local randomstring = "local "..k.." = tbl["..k.."]"
end
[/lua]
And I wanted to run randomstring as a function in thread 2. I have tried CompileString, but that just launches something like lua_run_cl (RunString)
I have also though about doing something like this
[lua]
for k,v in pairs(tbl) do
--scope 1
local randomstring = "function() local "..k.." = tbl["..k.."] end"
end
CompileString(randomstring, "somerandomfile")() --yes I know randomstring is nil here. It is an example.
[/lua]
and running it from CompileString, but I think that will just run it in another scope(scope1), since it is a function.
So basically I want to do a variable number of times of writing a local variable with a variable name to a scope.
Ideas?
- snip -
[B]WHAT?[/B]
I will correct the OP with scope instead of thread. Thanks
Also: no, that's not what I mean.
I have the string correct, I need to execute that string in the scope of the original function.
I made the op much easier to understand. I am bad at explaining things.
Uhh.. you want to turn this
[code]
-- let's say tbl is a table containing A:1 B:2 C:3
for k,v in pairs(tbl) do
--thread 1
local randomstring = "local "..k.." = tbl["..k.."]"
end[/code]
into this
[code]
local A = 1
local B = 2
local C = 3
[/code]
at runtime?
[QUOTE=cartman300;41616783]Uhh.. you want to turn this
[code]
-- let's say tbl is a table containing A:1 B:2 C:3
for k,v in pairs(tbl) do
--thread 1
local randomstring = "local "..k.." = tbl["..k.."]"
end[/code]
into this
[code]
local A = 1
local B = 2
local C = 3
[/code]
at runtime?[/QUOTE]
Basically. right now I have this in a table.
{"chat" = _G.chat, "othershit" = _G.othershit} (with a stolen copy from _G for each index)
I want to go through that table, and make a local variable for each one in a single scope
so it would act like it did this in the same scope,
local chat = tbl.chat
local othershit = tbl.othershit
But yes, how you described it.
Can't you just manually write it?
Why do you want to make some globals local?
I would just directly call them.
[QUOTE=cartman300;41616870]Can't you just manually write it?
Why do you want to make some globals local?
I would just directly call them.[/QUOTE]
I don't want to manually do each _G index. I want it to be automatic, so I don't have to update it for silly things like that.
I want to make local variables for a special something I am writing. I need the original copies so nothing overwrites them.
Found something to do it with.
[lua]
local _local = {}
_local.__index = _local
setmetatable(_G, _local)
_local = tbl
[/lua]
Sorry, you need to Log In to post a reply to this thread.