lua-users home
lua-l archive

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

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: []
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.