Jump to content

tolua exposure problems


Ywa
 Share

Recommended Posts

Hi everyone,

 

I want to expose a class and it's functions to Lua. This is the header I want to have converted:

#pragma once
#include "Leadwerks.h"

using namespace Leadwerks;

class Net { //tolua_export
private:
ENetHost * client;
public:
//tolua_begin
Net(void);
virtual ~Net(void);

virtual bool Net::Start(const bool isClient);
virtual bool Net::Think();

};
//tolua_end

 

Which returns the following lue-gluecode.cpp when using the automatic converter (which I include in the project):

/*
** Lua binding: luacommands
** Generated automatically by tolua++-1.0.92 on 03/02/14 10:30:32.
*/

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

#include "tolua++.h"

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

#include "Net.h"

/* function to release collected object via destructor */
#ifdef __cplusplus

static int tolua_collect_Net (lua_State* tolua_S)
{
Net* self = (Net*) tolua_tousertype(tolua_S,1,0);
Mtolua_delete(self);
return 0;
}
#endif


/* function to register type */
static void tolua_reg_types (lua_State* tolua_S)
{
tolua_usertype(tolua_S,"Net");
}

/* method: new of class Net */
#ifndef TOLUA_DISABLE_tolua_luacommands_Net_new00
static int tolua_luacommands_Net_new00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,"Net",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
{
Net* tolua_ret = (Net*) Mtolua_new((Net)());
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Net");
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* method: new_local of class Net */
#ifndef TOLUA_DISABLE_tolua_luacommands_Net_new00_local
static int tolua_luacommands_Net_new00_local(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,"Net",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
{
Net* tolua_ret = (Net*) Mtolua_new((Net)());
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Net");
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* method: delete of class Net */
#ifndef TOLUA_DISABLE_tolua_luacommands_Net_delete00
static int tolua_luacommands_Net_delete00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Net",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Net* self = (Net*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'delete'", NULL);
#endif
Mtolua_delete(self);
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'delete'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* method: Net::Start of class Net */
#ifndef TOLUA_DISABLE_tolua_luacommands_Net_Net__Start00
static int tolua_luacommands_Net_Net__Start00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Net",0,&tolua_err) ||
!tolua_isboolean(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Net* self = (Net*) tolua_tousertype(tolua_S,1,0);
const bool isClient = ((const bool) tolua_toboolean(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Net::Start'", NULL);
#endif
{
bool tolua_ret = (bool) self->Net::Start(isClient);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'Net__Start'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* method: Net::Think of class Net */
#ifndef TOLUA_DISABLE_tolua_luacommands_Net_Net__Think00
static int tolua_luacommands_Net_Net__Think00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Net",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Net* self = (Net*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Net::Think'", NULL);
#endif
{
bool tolua_ret = (bool) self->Net::Think();
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'Net__Think'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* Open function */
TOLUA_API int tolua_luacommands_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);
#ifdef __cplusplus
tolua_cclass(tolua_S,"Net","Net","",tolua_collect_Net);
#else
tolua_cclass(tolua_S,"Net","Net","",NULL);
#endif
tolua_beginmodule(tolua_S,"Net");
tolua_function(tolua_S,"new",tolua_luacommands_Net_new00);
tolua_function(tolua_S,"new_local",tolua_luacommands_Net_new00_local);
tolua_function(tolua_S,".call",tolua_luacommands_Net_new00_local);
tolua_function(tolua_S,"delete",tolua_luacommands_Net_delete00);
tolua_function(tolua_S,"Net__Start",tolua_luacommands_Net_Net__Start00);
tolua_function(tolua_S,"Net__Think",tolua_luacommands_Net_Net__Think00);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);
return 1;
}


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

 

I also added the required inclusion in main.cpp:

if (Interpreter::L==NULL) Interpreter::Reset();
tolua_luacommands_open(Interpreter::L);

 

However, when launching the project (compilation is fine) it gives an error at my App.lua script. Script runs fine without the lua-gluecode.cpp inclusion.

 

errorleadwerks_32dc.png

 

First couple of lines:

require "Scripts/libs/math.lua"
require "Scripts/libs/table.lua"
require "Scripts/libs/dataDumper.lua"

 

Removing these lines as a test causes the script to hang at the creation of Window.

 

Does anyone have any idea what's going on here?

 

Thanks in advance!

Link to comment
Share on other sites

Yes, I've managed to get it somewhat working.

 

For others who want a solution aswell:

- Make sure to name your tolua++ package something else than luacommands. I used luacom

- Write a header file for your lua-gluecode (example is down here).

- Make sure you call the right function in the main.cpp code (code also down here).

 

lua-gluecode.h

#pragma once
#include "Leadwerks.h"

using namespace Leadwerks;

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

 

Before App->Start() in main.cpp

if (Interpreter::L==NULL) Interpreter::Reset();
tolua_luacom_open(Interpreter::L);

 

Edit: Hereby I also include an example class header which is succesfully parsed by tolua++.

 

#pragma once
#include "Leadwerks.h"

using namespace Leadwerks;

class Net { //tolua_export
private:
ENetHost * client;
public:
//tolua_begin
int red;

Net(void);                          // constructor 1
~Net(void);                         // destructor

   bool Start(const bool isClient);
void Think(void);

};
//tolua_end

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...