[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Accessing functions from C
- From: David Bhowmik <david.bhowmik@...>
- Date: Tue, 2 Apr 2002 10:51:08 +0100
I suppose I should add that functions are like every other lua data type.
There is a generic structure lua_TObject which can be a string, number,
userdata, function etc. The global table (L->gt) is a hash table of names to
these objects. In the case of a variables it is variable name and value pair
in the case of funcitons this means function name and function closure pair.
The closure contains all you need to call the lua code by dumping it on the
stack which itslf is a load of lua_TObjects
*L->top = function;
L->top++;
//add args
lua_call(L, noArguments, LUA_MULTRET ); // last arg is no return values
expected 0-n or LUA_MULTRET
have fun
Dave
-----Original Message-----
From: David Bhowmik [mailto:david.bhowmik@creaturelabs.com]
Sent: 02 April 2002 10:41
To: Multiple recipients of list
Subject: RE: Accessing functions from C
bool GetFunction(lua_State *L, char functionName[], lua_TObject &function,
int &argsExpected)
{
function = *luaH_getstr(L->gt, luaS_new(L, functionName));
if(ttype(&function) != LUA_TFUNCTION)
return false;
// check arguments
Closure *cl = clvalue(&function);
const Proto *const tf = cl->f.l;
argsExpected = tf->numparams;
return true;
}
-----Original Message-----
From: db@tex.com [mailto:db@tex.com]
Sent: 02 April 2002 10:23
To: Multiple recipients of list
Subject: Accessing functions from C
I have what I think is an obvious question, that I cant find the answer to.
Here is a code fragment:
xxx("string", function () ...whatever... end)
xxx("another_string", a_previously_declared_function)
Function xxx(), a C function, takes two parameters, namely a string,
and a function, either named or anonymous. This function needs to store
both parameters. It does so in a mechanism outside of lua. The first
parameter, a string, is trivial. How do I retreive a persistent
reference to the second, the function? The list of provided
access functions does not seem to include a lua function retreiver,
only a C function retreiver.
The reason for this is so that the stored functions can be called
later from another C function. Thuis I need a persistent "pointer"
I can use at a random time.
Thanks.