lua-users home
lua-l archive

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


Nevermind, I solved it, I put '$hfile "class1.h"' in my package. :-)

Thanks!

Ariel Manzur wrote:
you don't use tolua to generate the pkg file. The pkg file is
generated by you, that's where you specify the interface you want to
bind. in this case, you would create 'class.pkg' with something like:

class Class1 {
               void AddOne();
};

and then run 'tolua++ -o class1_Lua.cpp class1.pkg' (note that the
output goes to a .cpp file). Then compile the cpp file and link with
the rest of your stuff.

Hope that helps..

Ariel.

On 6/20/07, L-28C <kixdemp@gmail.com> wrote:
Hello everyone!

OK, I used these commands:

tolua++ class1.h >> class1.pkg
tolua++ -o class1_Lua.h class1.pkg
g++ main.cpp class1.cpp -ltolua++

GCC gives me this BS:
-----------------------------
In file included from main.cpp:6:
class1_Lua.h: In function `int
tolua_class1_tolua_class1_open00(lua_State*)':
class1_Lua.h:37: error: `tolua_ret' has both `extern' and initializer
class1_Lua.h:37: error: expected primary-expression before "extern"
class1_Lua.h:37: error: expected `)' before "extern"
class1_Lua.h: In function `int
tolua_class1_tolua_class1_open01(lua_State*)':
class1_Lua.h:90: error: `tolua_ret' has both `extern' and initializer
class1_Lua.h:90: error: expected primary-expression before "extern"
class1_Lua.h:90: error: expected `)' before "extern"
class1_Lua.h: In function `int tolua_class1_luaopen_class100(lua_State*)':
class1_Lua.h:115: error: `tolua_ret' has both `extern' and initializer
class1_Lua.h:115: error: expected primary-expression before "extern"
class1_Lua.h:115: error: expected `)' before "extern"
-----------------------------

Did I do something wrong? Here's my files:

main.cpp:
-----------------------------
#include <tolua++.h>

#include "class1_Lua.h"

int main()
{
}

-----------------------------


class1.cpp:
-----------------------------
#include "class1.h"

void Class1::AddOne()
{
        ++num;
}

-----------------------------


class1.h:
-----------------------------
#ifndef CLASS1
#define CLASS1

class Class1
{
        int num;

        public:
                void AddOne();
};

#endif // CLASS1

-----------------------------

And here's the faulty one, class1_Lua.h:
-----------------------------
/*
** Lua binding: class1
** Generated automatically by tolua++-1.0.92 on 06/20/07 06:04:29.
*/

#ifndef __cplusplus
#include "stdlib.h"
#endif
#include "string.h"

#include "tolua++.h"

/* Exported function */
TOLUA_API int  tolua_class1_open (lua_State* tolua_S);


/* function to register type */
static void tolua_reg_types (lua_State* tolua_S)
{
}

/* function: tolua_class1_open */
#ifndef TOLUA_DISABLE_tolua_class1_tolua_class1_open00
static int tolua_class1_tolua_class1_open00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
  tolua_Error tolua_err;
  if (
      !tolua_isnoobj(tolua_S,1,&tolua_err)
  )
   goto tolua_lerror;
  else
#endif
  {
   lua_State* tolua_S =  tolua_S;
   {
TOLUA_API int tolua_ret = (TOLUA_API int) tolua_class1_open(tolua_S);
    tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
   }
  }
  return 1;
#ifndef TOLUA_RELEASE
  tolua_lerror:
  tolua_error(tolua_S,"#ferror in function
'tolua_class1_open'.",&tolua_err);
  return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* function: tolua_reg_types */
#ifndef TOLUA_DISABLE_tolua_class1_tolua_reg_types00
static int tolua_class1_tolua_reg_types00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
  tolua_Error tolua_err;
  if (
      !tolua_isnoobj(tolua_S,1,&tolua_err)
  )
   goto tolua_lerror;
  else
#endif
  {
   lua_State* tolua_S =  tolua_S;
   {
    tolua_reg_types(tolua_S);
   }
  }
  return 0;
#ifndef TOLUA_RELEASE
  tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'tolua_reg_types'.",&tolua_err);
  return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* function: tolua_class1_open */
#ifndef TOLUA_DISABLE_tolua_class1_tolua_class1_open01
static int tolua_class1_tolua_class1_open01(lua_State* tolua_S)
{
  tolua_Error tolua_err;
  if (
      !tolua_isnoobj(tolua_S,1,&tolua_err)
  )
   goto tolua_lerror;
  else
  {
   lua_State* tolua_S =  tolua_S;
   {
TOLUA_API int tolua_ret = (TOLUA_API int) tolua_class1_open(tolua_S);
    tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
   }
  }
  return 1;
tolua_lerror:
  return tolua_class1_tolua_class1_open00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE

/* function: luaopen_class1 */
#ifndef TOLUA_DISABLE_tolua_class1_luaopen_class100
static int tolua_class1_luaopen_class100(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
  tolua_Error tolua_err;
  if (
      !tolua_isnoobj(tolua_S,1,&tolua_err)
  )
   goto tolua_lerror;
  else
#endif
  {
   lua_State* tolua_S =  tolua_S;
   {
    TOLUA_API int tolua_ret = (TOLUA_API int)  luaopen_class1(tolua_S);
    tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
   }
  }
  return 1;
#ifndef TOLUA_RELEASE
  tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'luaopen_class1'.",&tolua_err);
  return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* Open function */
TOLUA_API int tolua_class1_open (lua_State* tolua_S)
{
  tolua_open(tolua_S);
  tolua_reg_types(tolua_S);
  tolua_module(tolua_S,NULL,0);
  tolua_beginmodule(tolua_S,NULL);

tolua_function(tolua_S,"tolua_class1_open",tolua_class1_tolua_class1_open00); tolua_function(tolua_S,"tolua_reg_types",tolua_class1_tolua_reg_types00);

tolua_function(tolua_S,"tolua_class1_open",tolua_class1_tolua_class1_open01); tolua_function(tolua_S,"luaopen_class1",tolua_class1_luaopen_class100);
  tolua_endmodule(tolua_S);
  return 1;
}


#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
  TOLUA_API int luaopen_class1 (lua_State* tolua_S) {
  return tolua_class1_open(tolua_S);
};
#endif
-----------------------------

Anyone know what the problem is? Thanks! (And sorry for the long message...)