[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Forwarding function calls from Lua->C->...
- From: Reuben Thomas <rrt1001@...>
- Date: Thu, 18 Jan 2001 00:04:08 +0000 (GMT)
For my EPOC port of Lua I have written an interface to OPL, EPOC's
BASIC-like language. The interface is written in C++. I want to be able to
register OPL routines in Lua. The way I imagine doing this is having an OPL
interface routine LuaRegister:(state&,f$) that takes the name of an OPL
So far, so good. But what do I actually register when I call
lua_register(state, ...)? I can't register an OPL function directly, so I
have to give the address of some C(++) function in my interface DLL. But if
I always give the same function, then how do I know which registered OPL
function was supposed to be called when Lua makes the call to C?
I suppose I want a way of fixing a parameter of the call that Lua makes to
be the name of the OPL function, or the equivalent.
Note that I can't just have one C++ function per OPL function I want to
register, as I don't want to have to recompile the C++ component each time I
want to register a new function in my OPL program; from the C++ interface's
point of view, I want to register new OPL functions dynamically.
I suppose I can always execute:
lua_dostring(L, "luaname = function(a1,a2,a3) _opl(\"oplname\",a1,a2,a3) end");
where _opl is the C++ dispatcher, which I register as normal with
lua_register and a1,a2,a3 are the arguments to the OPL procedure (this bit
of the string is constructed at registration-time). However, it all looks a
little fragile (plus of course, there's the run-time parsing overhead,
though I suppose I shouldn't be registering too many functions!).
Any suggestions for better ways of doing this? (Sorry if I've missed
something on the mailing list already.)
A hint: OPL is traditionally BASIC-like in its type system: strings, ints
(big and small) and floats, plus one-dimensional arrays. I would envisage
only supporting ints, floats and strings in the calling interface, and
recording type information when each OPL function is registered so that the
Lua quantities can be converted appropriately for argument passing.
http://sc3d.org/rrt/ | free, a. already paid for (Peyton Jones)