[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Loading chunks
- From: "Guy Davidson" <guy@...>
- Date: Fri, 17 Feb 2006 12:41:30 -0000
I'm having trouble invoking a loaded chunk.
Here's a simple piece of Lua:
for i=1,10 do
This is kept in a text file called test.lua.
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.
Then it calls
(where lua is the lua_State*) which pushes "print_loop", the function name declared in the chunk, on the stack. I then call
which exchanges the string "print_loop" for a function. However, NIL is appearing at the top of the stack instead. Now, my decision to call lua_gettable with LUA_GLOBALSINDEX is informed by the sample code in section 3.14 of the documentation. I am assuming that, when the chunk is loaded, all its declared objects (functions and variables) are added to the LUA_GLOBALSINDEX table, using the identifier as the key. I'm having trouble finding similar examples from the library code.
Any clues where I'm going wrong here?
While I'm waiting I'll write table diagnostics...