Page 1 of 1

Using tolua++ with C++?

Posted: Tue Oct 19, 2010 15:40
by aaron1a12
Hey, can anyone point me out to a simple, user-friendly, tutorial on how to integrate C++ functions into Lua?

I heard CEGUI uses a custom build of tolua++ so that's why I'm posting here.

Thing is as a newbie in software programming I have no friggin' idea on how to get MY c++ functions into Lua. I mean how did CEGUI do it? logger:logEvent works fine and it's a C++ bind, isn't it?

On this post (http://www.cegui.org.uk/phpBB2/viewtopic.php?f=2&t=5204&p=24883&hilit=tolua) they discuss something like "execute cegui/cegui/src/ScriptingModules/LuaScriptModule/package/make.dat", is tolua++ a command line executable?


:?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?:

Re: Using tolua++ with C++?

Posted: Wed Oct 20, 2010 20:24
by aaron1a12
Anyone?

Re: Using tolua++ with C++?

Posted: Fri Oct 22, 2010 10:34
by aaron1a12
???

Re: Using tolua++ with C++?

Posted: Fri Oct 22, 2010 18:56
by Jamarr
aaron1a12 wrote:I have no friggin' idea on how to get MY c++ functions into Lua.


This is a tolua++ issue, not a CEGUI issue. If you want to learn how to use tolua++ then you should read the tolua++ manual.

Re: Using tolua++ with C++?

Posted: Sun Oct 24, 2010 11:21
by aaron1a12
very funny

Re: Using tolua++ with C++?

Posted: Tue Dec 21, 2010 19:08
by uelkfr
I got demo8.lua working with my CEGUI learning framework. But tolua++ is to hard to understand. You know sometimes a creator is a good student, sometimes is a good teacher. This is the first case. Both Tutorials:Creating_a_scriptable_interface_using_CEGUI and tolua++ manual are bad for common understanding. So is there any way to call my C++ function or change C++ variable from demo8.lua without using tolua++ with only current CEGUI and Lua interaction?

Re: Using tolua++ with C++?

Posted: Tue Dec 21, 2010 20:31
by Mikademus
I really wish I could help you but I think Jamarr is right in that you will probably not get any answers here. Have you looked for any dedicated tolua++ communities, or gone to some of the major lua hubs? Indeed a boring answer to get, I know, but perhaps better than silence...

Re: Using tolua++ with C++?

Posted: Tue Dec 21, 2010 21:33
by uelkfr
THIS HELPED A LOT!!!
http://www.cegui.org.uk/wiki/index.php/ ... _Interface

But I didn't used namespace, classes, typedefs, variables, constants, just tried to do simple job, I tried to call C function from Lua

Code: Select all

// C function
bool MenuItemExit_OnButtonClick(const CEGUI::EventArgs& pEventArgs)
{
   glfwCloseWindow();
   return true;
}


Code: Select all

-- Lua code
function MenuItemExitHandler(args)
   return MenuItemExit_OnButtonClick(args);
end

...initialization skipped due its not related to subject...

-- subscribe required events, i can place here "MenuItemExit_OnButtonClick" directly, but i will need to handle it in Lua in future, save project before close, etc
winMgr:getWindow("root/MenuitemExit"):subscribeEvent("Clicked", "MenuItemExitHandler")


Then I created .pkg file, but only one .pkg, not two .pkg files like in tutorial. Tutorial more complex.
Then I compiled .pkg using .bat file. Now I'm thinking to integrate .bat into prebuild step of MSBuild of Visual Studio 2010. But I want this step only if .pkg or .hpp file changed.

Code: Select all

REM Create lua interface
tolua++cegui_Static.exe -n Sample_FirstWindow -H Sample_FirstWindow_reg.hpp -o Sample_FirstWindow_reg.cpp Sample_FirstWindow.pkg
pause


Then I attached this "Sample_FirstWindow_reg.hpp" to my code. And used this glue-creator function in initialization step:

Code: Select all

#include "Sample_FirstWindow_reg.hpp"
...
void initialiseSample()
{
    using namespace CEGUI;

    // create a script module.
    LuaScriptModule& scriptmod(LuaScriptModule::create());

    // tell CEGUI to use this scripting module
    System::getSingleton().setScriptingModule(&scriptmod);

    tolua_Sample_FirstWindow_open( scriptmod.getLuaState() );

    // execute the procgen.lua script which controls the rest of this demo
    System::getSingleton().executeScriptFile("procgen.lua");
}


Screenshot
Image

Then I click File -> Exit it calls Lua handler function, which calls C function, which calls glfwCloseWindow(), which marks to break main event loop.

Procgen Studio is program name, 0-1D Function is my future software developer company name.