[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to push function on the stack
- From: "Thomas Lefort" <thomas.lefort@...>
- Date: Fri, 9 Mar 2007 04:08:56 +0100
I'd like someone to point me to a sample source on how to push function on the stack.
const
char* code = "function
() print('hello world') end";
How would one go about pushing code as a function? And also, how do I later retrieve it? A snippet of code would be greatly appreciated.
See loadstring:
http://www.lua.org/manual/5.1/manual.html#luaL_loadstring
You'll just have to prefix your sample code with "return " to make it
a valid chunk.
Then, compile it:
luaL_loadstring(L, code);
And run the chunk to get your hello function on top of the stack:
lua_pcall(L, 0, 1, 0);