About Store Forum Documentation Contact



Post Reply 
Lua + Wrapper and boost
Author Message
monolith Offline
Member

Post: #1
Lua + Wrapper and boost
Hello,

has anyone been able to add lua + one of the wrappers (like luabind, toLua or diluculum) to an Esenthel application?

I've been trying for more than a week now and all I've succeeded is in adding basic lua, but not any of the wrappers, since they all depend on boost, which doesn't compile in Esenthel projects. At least in my vs2008 express projects.

Any help is appreciated.
Thanks in advance.
01-15-2010 08:10 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #2
RE: Lua + Wrapper and boost
I'm working with LUA plugin to Esenthel and today I will release first version without luabind. I tried to add luabind but luabind have diffrent project settings than Esenthel
01-16-2010 06:37 AM
Find all posts by this user Quote this message in a reply
monolith Offline
Member

Post: #3
RE: Lua + Wrapper and boost
Yes, it's the same problem I've been having. The problem is not so much luabind itself, but boost. I just can't figure out what doesn't mix well between esenthel and boost.

I'm glad to see more people are interested in adding lua to their games. I'll be waiting to see what you come up with Barthap.
01-16-2010 07:12 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #4
RE: Lua + Wrapper and boost
Here I'll show my template for LUA scripts. It is simple class where I show you how to define functions in LUA. This class doesnt have only 1 example: function Text() wich calls function D.text().

Lua.h
Code:
#pragma once

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

class LUA
{
    void define_funcs();    //here uou can define your function used in LUA
protected:
    lua_State* L;            //main LUA object
    
public:
    
    void init();            //initialization
    void del();                //deinitialization

    void Run(const char* path);        //run script from path

    void onInit();            //function calls function INIT()    in script
    void onUpdate();        //function calls function UPDATE()    in script
    void onDraw();            //function calls function DRAW()    in script
    void onShut();            //function calls function SHUT()    in script
};

Lua.cpp
Code:
#include "stdafx.h"
#include "main.h"

int DText(lua_State *L); //function DText wich calls D.text

void LUA::define_funcs()
{
    lua_register(L, "Text", DText); //Registers function DText() as Text() in script    
}
void LUA::init()
{
    /* initialization Lua */
    L = lua_open();
    /* loading main libraries Lua */
    luaL_openlibs(L);

  // registration functions in LUA
    define_funcs();
}
void LUA::del()
{
    /* closing LUA */
    lua_close(L);
}
//////
void LUA::Run(const char* script)
{
    luaL_dofile(L, script);
}
///////
void LUA::onInit()
{
    lua_getglobal(L, "Init");
    lua_call(L, 0, 0);
}
void LUA::onUpdate()
{
    lua_getglobal(L, "Update");
    lua_call(L, 0, 0);
}
void LUA::onDraw()
{
    lua_getglobal(L, "Draw");
    lua_call(L, 0, 0);
}
void LUA::onShut()
{
    lua_getglobal(L, "Shut");
    lua_call(L, 0, 0);
}
/////Funcs from LUA/////
int DText(lua_State *L)
{
    Flt pos_x = lua_tonumber(L, 1);
    Flt pos_y = lua_tonumber(L, 2);
    CChar8* text = lua_tostring(L, 3);
    D.text(pos_x, pos_y, text);
    return 0;
}

in main.h you must add #include "lua.h"
next in VS2008 in menu Project click Properties, in left window select Configuration Properties -> Linker -> Input and in Additional dependencies add Lua5.1.lib (libs and dlls in attatchament)

Use example:
define LUA class instantion:
Code:
LUA Lua
in init():
Code:
Lua.init();
Lua.Run("sample.lua");
in draw(), we dont use update and shut becouse this example shows only D.text():
Code:
Lua.onDraw(); //if you use update in your script, in update() should be Lua.onUpdate()

WARNING: DLL files from attatchament must be on user(player) computer in game folder with .exe file or in C:\Windows\system32


It was example for LUA without luabind or boost, now I will try add luabind


Attached File(s)
.zip  lua.zip (Size: 90.69 KB / Downloads: 17)
01-17-2010 07:22 AM
Find all posts by this user Quote this message in a reply
monolith Offline
Member

Post: #5
RE: Lua + Wrapper and boost
Awesome! It works very well.

The great thing about the other wrappers, though, is how well they handle variables coming and going from C++ and Lua. If it wasn't for that, this bit of code here would be all everyone really needed.

Looking forward to your luabind results.

(I didn't use your zipfile, since I already had lua set up, I just used the code you posted. You forgot to add Lua.del() to Shut(), apart from that, it worked just like it is)

You rock smile
01-17-2010 09:46 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #6
RE: Lua + Wrapper and boost
in my zipfile I packed oryginal LUA libs and dlls, if you install LUA, my code can work without my zipfile
01-18-2010 07:05 AM
Find all posts by this user Quote this message in a reply
Kevin Offline
Member

Post: #7
RE: Lua + Wrapper and boost
I tried to add luabind to my project, but I get couple of linker errors...
is there any 'trick' to make luabind work with EE?
I want to use this wrapper, because most of the others don't support classes (or only limited).

If there is no 'trick',
@Esenthel: Is there any change, that you'll change project settings, so that luabind works together with EE?
01-25-2010 06:30 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #8
RE: Lua + Wrapper and boost
I've never tried LUA but I think you can play around with projects settings and modify them, maybe they'll work
01-25-2010 08:18 PM
Find all posts by this user Quote this message in a reply
monolith Offline
Member

Post: #9
RE: Lua + Wrapper and boost
I haven't managed to get luabind working, or any other library that depends on boost.

I think boost is incompatible with some of the libraries the esenthel engine links to. And possibly some naming conflicts, with strings and such - but I wouldn't bet on this since they have diferent namespaces.

There isn't much documentation about using boost on windows when you have problems, generally you only have basic "how to's" on how to setup you visual studio project.

I even started a a default vs2008 project, got it to compile esenthel with all the defaults, but as soon as I added boost. down the drain it went. I even installed several versions of boost.

Hope you guys have better luck.
01-26-2010 06:55 AM
Find all posts by this user Quote this message in a reply
Kevin Offline
Member

Post: #10
RE: Lua + Wrapper and boost
I just managed to get luabind working together with EE, maybe I'll write a short article on that at the EE wiki in a few days.
01-27-2010 02:13 PM
Find all posts by this user Quote this message in a reply
monolith Offline
Member

Post: #11
RE: Lua + Wrapper and boost
please do, I'd be very grateful smile
01-27-2010 04:53 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #12
RE: Lua + Wrapper and boost
yep, everyone who want to contribute can just register on wiki,
and then create a new page here - http://www.esenthel.com/wiki/index.php?t...er_Section
01-27-2010 05:14 PM
Find all posts by this user Quote this message in a reply
Kevin Offline
Member

Post: #13
RE: Lua + Wrapper and boost
I've written the short article.
Link
01-30-2010 01:47 PM
Find all posts by this user Quote this message in a reply
monolith Offline
Member

Post: #14
RE: Lua + Wrapper and boost
Thanks, you rock! smile

It worked very well, just had to switch my project to multi-threaded instead of multi-threaded dll.
02-01-2010 07:36 PM
Find all posts by this user Quote this message in a reply
Post Reply