kayaven
|
  |
| Joined: 01 Jun 2011 |
| Total Posts: 30 |
|
| |
|
rabbidog
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 804 |
|
| |
|
kayaven
|
  |
| Joined: 01 Jun 2011 |
| Total Posts: 30 |
|
|
| 30 Jun 2013 09:18 AM |
Is there an other way, like
a = "hello" function(a) loadstring(print(a)) end
this doesnt work, is there some other way that you just gave me? |
|
|
| Report Abuse |
|
|
kayaven
|
  |
| Joined: 01 Jun 2011 |
| Total Posts: 30 |
|
|
| 30 Jun 2013 09:37 AM |
| Nevermind, finally found out :D |
|
|
| Report Abuse |
|
|
rabbidog
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 804 |
|
| |
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 30 Jun 2013 12:50 PM |
Here's how I did it in my free time:
function runCodewithVariables(code, vars) local func = loadstring(code) local env = getfenv(func) for i, v in pairs(vars) do env[i] = v end return setfenv(func, env)() end
print(runCodewithVariables("print(var1) return something", {var1="Hi everyone", something="HI"}))
It is innefficient, yes. But I was half asleep at the time, so I just did that. |
|
|
| Report Abuse |
|
|
|
| 30 Jun 2013 12:51 PM |
Loadstring returns a variadic function.
local a, b, c = loadstring("return ...")(1, 2, 3) print(a, b, c) --> 1 2 3 |
|
|
| Report Abuse |
|
|