lua-users home
lua-l archive

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


Hi all.

I've been using lua and tolua recently, and I am very pleased with both of
them.  Many thanks and gratitude to their respective authors.

Has anyone attempted and successfully modified tolua?  Modification in the
sense of controlling or changing tolua's output.

For example, here is a usual tolua output fragment:

static int toluaI__sys_setactivestate00(lua_State* tolua_S)
...

I need to modify this into:
static int __cdecl toluaI__sys_setactivestate00(lua_State* tolua_S)
...

The reason for the explicit inclusion of __cdecl is because I plan to
compile the page with a __fastcall by default.  This is because its #include
files are such that, and I am unable to bind them without including them.
Most of the #includes have inline functions inside them that need the
default __fastcall.  Modifying the #include files themselves are not an
option, as I cannot recompile the API without the source code.

I've looked at tolua's code, and found this in tolua.c:

#if 1
 {
  int tolua_tolualua_open(lua_State* L);
  tolua_tolualua_open(L);
 }
#else
 {
  int i;
  char* p;
  char  path[BUFSIZ];
  char* files[] = {
                   "basic.lua",
                   "feature.lua",
                   "verbatim.lua",
                   "code.lua",
                   "typedef.lua",
                   "container.lua",
                   "package.lua",
                   "module.lua",
                   "define.lua",
                   "enumerate.lua",
                   "declaration.lua",
                   "variable.lua",
                   "array.lua",
                   "function.lua",
                   "operator.lua",
                   "class.lua",
                   "clean.lua",
                   "doit.lua",
                   NULL
                  };
  strcpy(path,argv[0]);
  p = strrchr(path,'/');
  p = (p==NULL) ? path : p+1;
  for (i=0; files[i]; ++i)
  {
   sprintf(p,"%s",files[i]);
   lua_dofile(L,path);
  }
 }

Obviously the "#if 1" is a switch either to use the integrated lua code of
tolua (tolualua.c) or its external counterpart(s), which are the *.lua
files.

The *.lua files contain the actual generation code and found this in
function.lua:
-- Write binding function
-- Outputs C/C++ binding function.
function classFunction:supcode ()
 local nret = 0      -- number of returned values
 local class = self:inclass()
 local _,_,static = strfind(self.mod,'^%s*(static)')

 if class then
  output("/* method:",self.name," of class ",class," */")
 else
  output("/* function:",self.name," */")
 end
 output("static int",self.cname,"(lua_State* tolua_S)")
 output("{")

Seeing this, I modified the line 'output ("static int"...' to output
'("static int __cdecl "...'.
Also, I modified the #if 1 line in tolua.c so tolua.exe will use the *.lua
files instead of the internal version.

It seemed to work well and all, but unfortunately the output file it
generated was zero(0) bytes... it didnt contain anything.  I checked the
program and lua_dofile () returns success, so there isnt a problem with the
*.lua files (maybe).  All the required lua libraries were called (baselib,
iolib, strlib), so it couldnt be that.  Whats the big difference between the
internal version and the *.lua files, besides being internal?

I'm at a quandary now.  Anyone can lend me a little insight? :)



-Mark