Using tolua++ with C++?

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

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Using tolua++ with C++?

Postby aaron1a12 » Tue Oct 19, 2010 15:40

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?


:?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?:
I hate BBCode pls enable <b>HTML</b> ;)

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Using tolua++ with C++?

Postby aaron1a12 » Wed Oct 20, 2010 20:24

Anyone?
I hate BBCode pls enable <b>HTML</b> ;)

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Using tolua++ with C++?

Postby aaron1a12 » Fri Oct 22, 2010 10:34

???
I hate BBCode pls enable <b>HTML</b> ;)

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Using tolua++ with C++?

Postby Jamarr » Fri Oct 22, 2010 18:56

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.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Using tolua++ with C++?

Postby aaron1a12 » Sun Oct 24, 2010 11:21

very funny
I hate BBCode pls enable <b>HTML</b> ;)

uelkfr
Not too shy to talk
Not too shy to talk
Posts: 34
Joined: Tue Dec 14, 2010 16:57

Re: Using tolua++ with C++?

Postby uelkfr » Tue Dec 21, 2010 19:08

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?
helper to newbies

"i help you, dear newbie
but nobody helps me!"

User avatar
Mikademus
CEGUI MVP
CEGUI MVP
Posts: 130
Joined: Wed Mar 18, 2009 19:14

Re: Using tolua++ with C++?

Postby Mikademus » Tue Dec 21, 2010 20:31

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...

uelkfr
Not too shy to talk
Not too shy to talk
Posts: 34
Joined: Tue Dec 14, 2010 16:57

Re: Using tolua++ with C++?

Postby uelkfr » Tue Dec 21, 2010 21:33

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.
helper to newbies

"i help you, dear newbie
but nobody helps me!"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 24 guests