lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Friday 17 February 2006 7:45 am, Alex Queiroz wrote:
> Hallo,
>
> On 2/17/06, Guy Davidson <guy@creative-assembly.co.uk> 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.
>
>      Did you run this function?

i'll try to clarify Alex's suggestion:  luaL_loadfile() loads the chunk and 
compiles it, but it doesn't execute the chunk.  remember that a code like 
yours:

function foo()
-- ...
end

is just syntactic sugar for:

foo = function ()
-- ...
end

IOW, it constructs a function and then assigns it to a variable.  that 
assignment is what must be executed.  to execute that, you have to execute 
the chunk itself.  the function that you got in the stack is the whole chunk 
compiled and unexecuted.  only after running it you'll find your function(s 
and variables) in the global table

-- 
Javier

Attachment: pgpm0dsGwtaAb.pgp
Description: PGP signature