[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Loading chunks
- From: Romulo Bahiense <romulo@...>
- Date: Fri, 17 Feb 2006 10:51:27 -0300
Guy Davidson wrote:
My client C++ code calls luaL_loadfile with this filename.
> My stack diagnostics tell me a Lua function is on the top
> of the stack now.
Right. The chunk is at the top of the stack. You will have to call it,
so it will be able to register print_loop in the globals table.
// Load the code
luaL_loadfile(L, "test.lua");
// Execute the chunk
lua_call(L, 0, 0);
// You know what to do from now on :)
lua_pushstring(L, "print_loop");
lua_gettable(L, LUA_GLOBALSINDEX);
lua_call(L, 0, 0);
The Lua version of this code would be:
> local chunk = loadfile("test.lua")
> print(type(chunk))
function: ...
> print(print_loop)
nil
> chunk()
> print(print_loop)
function: ...
Hope it helps
--rb