lua-users home
lua-l archive

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

Did you run the loaded script before exploring LUA_GLOBALSINDEX?

A "loaded" script (such as returned from loadfile) is a Lua function.  In
order to obtain the functions declared in the script you must run the script
rather than just load it.

Remember that in Lua...

function MyFunc() do

is equivalent to...

MyFunc = function() do

which is to say that it assigns a function value to the global "MyFunc".

If after you've got this working for one script file, you're architecture
calls for the use of multiple script files all with the same names for their
functions, and the functions lifetimes need to overlap, then you will want
to investigate function "environments" (lua_setfenv, and lua_getfenv) and

-----Original Message-----
[]On Behalf Of Francesco
Sent: Sunday, June 06, 2004 12:34 PM
Subject: Retrieving the list of the functions declared in a script file

Hi all,
    I'm a Lua newbie and I'm trying to integrate Lua scripting in one of my
C++ applications.
The scripting I require is very simple: the program must load a script file
and then run a specific functions which should be
declared inside it.

My problem is that I don't know how to get the list of the functions
declared inside the script file I load (maybe with the number
of arguments they take...) .
CINT & UnderC provide some methods to do it.... in Lua I tried to explore
the table at index LUA_GLOBALSINDEX, but I didn't find the
functions declared in the lua scripts loaded... how can I do it ?

If you need, I attach the CPP source file and the LUA script file I worked

Thank you very much indeed,
Francesco Montorsi