[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Passing C struct values automatically to Lua
- From: Nevin Flanagan <Alestane@...>
- Date: Fri, 6 Nov 2009 07:46:24 -0500
On Nov 5, 2009, at 9:59 PM, zweifel wrote:
Second, Is there anyway of knowing inside a lua script,
automatically the name of the script itself.
I would like to have something like in bash shell, where the first
argument is the name of the program called. In Lua is there a way to
get the value passed to lua_pcall() inside the script called, in
order to know its own name automatically?
Thanks in advance,
Functions don't fundamentally have names in Lua. From the
documentation on the lua_Debug struct:
"name: a reasonable name for the given function. Because functions in
Lua are first-class values, they do not have a fixed name: some
functions can be the value of multiple global variables, while others
can be stored only in a table field. The lua_getinfo function checks
how the function was called to find a suitable name. If it cannot find
a name, then name is set to NULL. "
If you have access to the debug library inside your Lua environment,
debug.getinfo contains a function that you can use to retrieve
information like what name the function was called from.