[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Performance Question
- From: "Duncan Cross" <duncan.cross@...>
- Date: Thu, 8 Jan 2009 18:41:54 +0000
On Thu, Jan 8, 2009 at 6:20 PM, Raymond Jacobs <email@example.com>
Correct, the script doesn't change.
As for storing it; what does loadstring actually do; does it push the code and functions onto the stack?
or is it all wrapped up as a single function?
in such a case I guess I could use lua_ref, to create a ref to it for later use?
or what else would you suggest?
It compiles the string into a single Lua function and pushes that function onto the stack. If the only thing you're doing with this lua_State is running this single function over and over again, after it has been added to the stack by loadstring you can run it by doing this:
lua_pushvalue(L,-1); // get a copy of the function from the top of the stack (as calling it will remove it from the stack)
lua_call(L,0,0); // call the function (no parameters, no return value)
Repeating this fragment of code later will run the function again. If you are using the lua_State for other things, interleaved with calls to this function, it will probably not work.