Installing toLua

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

vimes
Just popping in
Just popping in
Posts: 10
Joined: Wed May 24, 2006 00:05

Installing toLua

Postby vimes » Wed Jun 07, 2006 05:22

I've begun to use the LUA scripting language and I'd like to call C++ functions from the LUA script... but it's been several hours that I've been unsuccessfully trying to install/build toLua++in order to create the package/binding and whatnot

So I'd like to know the simplest way to get Lua++ to work.

Here is what I've been doing
- if I understand [url=http://www.cegui.org.uk/wiki/index.php/Getting_Started_with_Lua_and_CEGUI) the wiki[/url] well, easy-to-build and easy-to-use version of lua and tolua++ are included in the 0.4.1 release.. the thing is that I've looked around for the sources but I could only find the lua_and_tolua++.lib.
- I even tried to compile toLua++ 1.0 by using lua_and_tolua++.lib as an input libary instead of lua_5.1.lib but I got a lot of unresolved symbol

Code: Select all

MSVCRT.lib(MSVCR80.dll) : error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _fclose already defined in LIBCMT.lib(fclose.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _isprint already defined in LIBCMT.lib(_ctype.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _isspace already defined in LIBCMT.lib(_ctype.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _fprintf already defined in LIBCMT.lib(fprintf.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _strchr already defined in LIBCMT.lib(strchr.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _strncat already defined in LIBCMT.lib(strncat.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _strcspn already defined in LIBCMT.lib(strcspn.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _isalnum already defined in LIBCMT.lib(_ctype.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _isdigit already defined in LIBCMT.lib(_ctype.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _iscntrl already defined in LIBCMT.lib(_ctype.obj)
MSVCRT.lib(MSVCR80.dll) : error LNK2005: _isalpha already defined in LIBCMT.lib(_ctype.obj)
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
tolua.obj : error LNK2019: unresolved external symbol _lua_objlen referenced in function _add_extra
tolua.obj : error LNK2019: unresolved external symbol _lua_getfield referenced in function _add_extra
tolua_map.obj : error LNK2001: unresolved external symbol _lua_getfield
tolua_push.obj : error LNK2001: unresolved external symbol _lua_getfield
tolua.obj : error LNK2019: unresolved external symbol _lua_createtable referenced in function _main
tolua_event.obj : error LNK2001: unresolved external symbol _lua_createtable
tolua_map.obj : error LNK2001: unresolved external symbol _lua_createtable
tolua.obj : error LNK2019: unresolved external symbol _lua_setfield referenced in function _main
tolua.obj : error LNK2019: unresolved external symbol _luaL_openlibs referenced in function _main
tolua.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _main
tolua_is.obj : error LNK2019: unresolved external symbol _lua_tolstring referenced in function _tolua_typename
tolua_to.obj : error LNK2001: unresolved external symbol _lua_tolstring
tolua_map.obj : error LNK2019: unresolved external symbol _lua_gc referenced in function _tolua_bnd_releaseownership

- I got the Lua sources and tried to get a lib out of it by compiling it with VC Express but it failed

I would be really grateful if someon could help me, Lua+CEGUI is really the most fitted solution for my project and I would hate not to use it.
Thanks

vimes
Just popping in
Just popping in
Posts: 10
Joined: Wed May 24, 2006 00:05

Postby vimes » Wed Jun 07, 2006 07:19

I've finally managed to get a precompiled version of toLua++ via irrLua package which you can find here
and with which I managed to create my cpp Lua file from a .pkg (i.e a modified .h header)
Here is the .pkg

Code: Select all

class GameEngine
{
public:

   // Returns the currently active state
   GameState* getCurrentState(){}

   // <SINGLETON>
   static GameEngine& getInstance();

};

and here is the .cpp obtained [i added #include "GameEngine.h",
#include "GameState.h" and using namespace Global;]

Code: Select all

/*
** Lua binding: LUAGameEngine
** Generated automatically by tolua++-1.0.7 on 06/07/06 17:03:28.
*/

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

#include "tolua++.h"
#include "GameEngine.h"
#include "GameState.h"

using namespace Global;
/* Exported function */
TOLUA_API int  tolua_LUAGameEngine_open (lua_State* tolua_S);


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

/* method: getCurrentState of class  GameEngine */
#ifndef TOLUA_DISABLE_tolua_LUAGameEngine_GameEngine_getCurrentState00
static int tolua_LUAGameEngine_GameEngine_getCurrentState00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"GameEngine",0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  GameEngine* self = (GameEngine*)  tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getCurrentState'",NULL);
#endif
  {
   GameState* tolua_ret = (GameState*)  self->getCurrentState();
   tolua_pushusertype(tolua_S,(void*)tolua_ret,"GameState");
  }
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'getCurrentState'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

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

/* Open function */
TOLUA_API int tolua_LUAGameEngine_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_cclass(tolua_S,"GameEngine","GameEngine","",NULL);
  tolua_beginmodule(tolua_S,"GameEngine");
   tolua_function(tolua_S,"getCurrentState",tolua_LUAGameEngine_GameEngine_getCurrentState00);
   tolua_function(tolua_S,"getInstance",tolua_LUAGameEngine_GameEngine_getInstance00);
  tolua_endmodule(tolua_S);
 tolua_endmodule(tolua_S);
 return 1;
}


Now, my problem is that I encounter this error

Code: Select all

07/06/2006 17:12:14 (Error)   Exception: (LuaScriptModule) Unable to execute scripted event handler: handleReturnToGame
[string "../datafiles/lua_scripts/demo8.lua"]:180: attempt to index global `LUAGameEngine' (a nil value)


when I attempt to execute the following function in my script

Code: Select all

-----------------------------------------
-- HandlerBack to Game
-----------------------------------------
function handleReturnToGame(args)

   local winMgr = CEGUI.WindowManager:getSingleton()
   local temp = winMgr:getWindow("Menu");
   temp:setVisible(false);
   local modelman = LUAGameEngine:getInstance()
   
end


Anyone has a clue why it is acting like this?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Wed Jun 07, 2006 16:37

You are exporting your class as GameEngine not LUAGameEngine
Also, do you call the tolua_LUAGameEngine_open to attach your binding to your Lua state?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Wed Jun 07, 2006 16:38

Also, CEGUILua uses lua 5.02, not 5.1
Dont mix them together

vimes
Just popping in
Just popping in
Posts: 10
Joined: Wed May 24, 2006 00:05

Postby vimes » Wed Jun 07, 2006 21:59

lindquist wrote:You are exporting your class as GameEngine not LUAGameEngine

Ok, so I replaced
LUAGameEngine.getInstance() with
GameEngine.getInstance()
lindquist wrote:Also, do you call the tolua_LUAGameEngine_open to attach your binding to your Lua state?

I tried to call it when I create the guiRenderer but because it is not referenced in LuaGameEngine.h I wrote (i.e the clean header identical to LUAGameEngine.pkg), the program wouldn't compile.
I figured I might need to use a .h generated by tolua so I used the command line

Code: Select all

tolua+ -H LUAGameEngine.h -o LUAGameEngine.cpp LUAGameEngine.pkg

and it generated this file

Code: Select all

/*
** Lua binding: LUAGameEngine
** Generated automatically by tolua++-1.0.7 on 06/08/06 07:54:45.
*/

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

which failed to compiled, VC express givin me the error :

Code: Select all

c:\documents and settings\dave\desktop\workingoutput\source\globalmain\code\luagameengine.h(7) : error C2144: syntax error : 'int' should be preceded by ';'
c:\documents and settings\dave\desktop\workingoutput\source\globalmain\code\luagameengine.h(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


I know this must be beginner and trivial stuff; I tried to follow the documentation of the tolua site and from the CEGUI wiki but lots of things remained unclear to me.

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Thu Jun 08, 2006 01:56

remove the TOLUA_API stuff from the generated files and it will compile properly

vimes
Just popping in
Just popping in
Posts: 10
Joined: Wed May 24, 2006 00:05

Postby vimes » Mon Jun 26, 2006 01:08

I solved it using another method : I added a tolua++ include and it worked :P


Return to “Help”

Who is online

Users browsing this forum: No registered users and 24 guests