lua-users home
lua-l archive

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


Hi all,

I don't know if the LUA list can also be used to talk about tolua++ problems, but maybe someone could help me out.
I've been playing around with tolua++ version 1.0.92 for a couple months, and have come into two strange behaviors in the code that it generates.

The first one seems to be really a bug, and it's about the "tolua_outside" keyword. Whenever I use it, I  get a "tolua_outside" inside the cpp file which messes up the compilation. Everything works fine when I delete manually every instance of "tolua_outside" from  the generated file though, and the keyword's functionality also works.
Here's an example:

Declaration in the PKG file:
  class HGE {
  public:
      static tolua_outside HGE* hgeCreate @ create(int ver);   
  };

Snippet of the generated cpp file:

   tolua_outside HGE* tolua_ret = (tolua_outside HGE*)  hgeCreate(ver);
   tolua_pushusertype(tolua_S,(void*)tolua_ret,"HGE");


The second strange issue is when declaring parameters as std::string in methods to be exposed by tolua++. After calling the method, tolua++ pushes every single std::string parameter onto the lua stack for a reason which is unkown to me.

Here's an example:

in the PKG file, I declare a method like this:

  class Engine
  {
  public:
     void doStuff(const std::string& p1, int p2, const std::string& p3, const char* p4);
  };

Now, this is a snippet of the cpp file generated by tolua++:

  // the parameter gathering part
  Engine* self = (Engine*)  tolua_tousertype(tolua_S,1,0);
  const std::string p1 = ((const std::string)  tolua_tocppstring(tolua_S,2,0));
  int p2 = ((int)  tolua_tonumber(tolua_S,3,0));
  const std::string p3 = ((const std::string)  tolua_tocppstring(tolua_S,4,0));
  const char* p4 = ((const char*)  tolua_tostring(tolua_S,5,0));

  // the actual method call
  self->doStuff(p1,p2,p3,p4);
  tolua_pushcppstring(tolua_S,(const char*)p1);
  tolua_pushcppstring(tolua_S,(const char*)p3);


See the two string being pushed into the stack after the call? And ONLY the std::string parameters are being pushed, which makes no sense.
I found out recently that my stack was getting huge for no apparent reason, and after looking at the values, I found out that every single std::string parameter of my exposed functions were also being pushed into the stack.

Is this a bug, or a feature? Is there a way to disable this behavior?
I'd appreciate any help.

Thanks!

--
Frederico Ferro Schuh