lua-users home
lua-l archive

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


>That way you could have an automated VCL->Lua binding at runtime using 
>the RTTI (Run Time Type Information)
I do not know a lot about rtti, but is it compatible with: lua_CFunction =
function(L: Plua_State): Integer; cdecl; Because that is the only type of
pascal(delphi) function that is compatible with use of lua.

>Maybe we could start a 'PascalToLua'
That's a good thing.

So we need: 
function to read global var
function to write global var
function to register funtion (already exists)
function to register class

The first three are easy. Here's some code:

//set global var A with value 10
//this pushes the globals table of state L
lua_pushvalue(L, LUA_GLOBALSINDEX);
//this sets a key in the globals table of L
lua_pushstring(L, 'a'); //Be aware lua vars are case sensitive!! a<>A
lua_pushnumber(L, 100); lua_settable(L, LUA_GLOBALSINDEX); // global a = 10
//end set

You must recognize the above wim.

Reading a global var from lua back to pascal goes like:

//read global var from lua
//this pushes the globals table of state L
lua_pushvalue(L, LUA_GLOBALSINDEX);
lua_pushstring(L, 'a');
lua_gettable(L, LUA_GLOBALSINDEX);  // global a
writeln('Delphi: '+floattostr(lua_tonumber(L, lua_gettop(l) ))); //end read

Now we need to find a way to publish a structure to lua that represents a
delphi class ( i believe that is what the tolua project does, but the c code
confuses me.) i made a go at it as you can see in a previous post, but it is
totaly not working.

>At this point, I'm pondering about create a Pascal project like 
>LuaCheia or LuaX or even a translation of the Lua to
>Pascal (which will be much easier to be done in FPC because of it's
compatibly with C). But I don't know if the work will 
> be worthy it. Specially because the synchronization with Lua changes (not
so difficult using a diff tool).
I do not think that is worth te effort. A wrapper 'PascalToLua' should be
enough.