Posted 05 April 2013 - 03:09 AM
I want to run code inside a program. I found solution for this:
someCode = "print("Yay!")
pcall(setfenv(loadstring(someCode),getfenv(1)))
but, I have 2 files. First is a startup file, which is running whole time, second is an api, where are functions.
And now, I want to run code from this api file, but with enviroment of startup.
Example:
startup file:
myapi file:
Problem is, this way,i can run functions inside myapi, byt not inside startup program. I know something is wrong with enviroment,
but I don't have enough experience with this. Basicly, I want to be able to run functions inside startup file like in this example.
Obviously I have much more difficult code, but I am stuck on this problem.
Thnx for help.
someCode = "print("Yay!")
pcall(setfenv(loadstring(someCode),getfenv(1)))
but, I have 2 files. First is a startup file, which is running whole time, second is an api, where are functions.
And now, I want to run code from this api file, but with enviroment of startup.
Example:
startup file:
function someFunction(argument)
if argument>0 then
print("Yay!")
else
print("Nah!")
end
end
os.loadAPI("myapi")
someCode = "someFunction(5)"
myapi.runThis(someCode)
myapi file:
function runThis(code)
pcall(setfenv(loadstring(code),getfenv(1)))
end
Problem is, this way,i can run functions inside myapi, byt not inside startup program. I know something is wrong with enviroment,
but I don't have enough experience with this. Basicly, I want to be able to run functions inside startup file like in this example.
Obviously I have much more difficult code, but I am stuck on this problem.
Thnx for help.