lua-users home
lua-l archive

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


> > Once you load it, running << chunk = loadfile("filename") >>,
> > Lua creates a new function that represents the chunk. Once
> > you call that function, running << chunk() >>,
>
> Are you saying that the chunk name I pass in the function
> lua_load becomes a strong reference to the functions it
> contains? Does it mean I have to set the loaded chunk
> name to nil?

No, that's not what he said.
lua_load << returns >> the new function on the stack, notice the assignment
of the return value in << chunk = loadfile("filename") >>.  If you want it
to hang around you'll need to assign a reference to it (i.e. a global
variable, make an entry in the registry, etc.).

The "chunk name" passed to lua_load is for debugging purposes only.