Rick Posted June 2, 2013 Share Posted June 2, 2013 You can make a Lua script that exposes a string property. This value for all your objects you could use json or whatever to format the data you need. In the script set the entity key value to this data. Then in C++ you can probably find a pretty lightweight json parser and get the entity data. I guess I'm not sure when the scripts Start() is called in relation to parsing the map in C++. Quote Link to comment Share on other sites More sharing options...
Josh Posted June 2, 2013 Share Posted June 2, 2013 Start() is called after all entities are loaded and flowgraph connections linked. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
pracedru Posted September 19, 2015 Share Posted September 19, 2015 Since i didn't have a solution to do a server-client data layer in Lua i decided to build one in C++. This is mainly due to being more familiar with multi threading in C++, And this kind of stuff needs to be in a separate thread from the 3D rendering thread, in my opinion. But i still wanted to use LUA for prefab scripting and all the other neat stuff Leadwerks. Here is what i did to make this work: I installed tolua++ on my development machine with sudo apt-get install libtolua++5.1-dev I build a class named ShotListener.h #pragma once #include "App.h" #include "Leadwerks.h" using namespace Leadwerks; class ShotListener { //tolua_export private: public: //tolua_begin ShotListener(void) { } // constructor 1 ~ShotListener(void){} // destructor void shot(Object* oEntity, float damage) { App *app = App::getInstance(); Entity * entity = (Entity*)oEntity; app->entityShot(entity, damage); return; } float getHealth(Object* oEntity) { App *app = App::getInstance(); Entity * entity = (Entity*)oEntity; float value = app->getEntityHealth(entity); return value; } }; I Made the App class into a Singleton, so that any Lua script can instantiate the ShotListener and call functions from the App. I made a tolua++ ShotListener.PCK file to match the ShotListener class: $#include "shot.h" class ShotListener { ShotListener(); ~ShotListener(); void shot(Object* oEntity, float damage); float getHealth(Object* oEntity); }; In the terminal i used the following command to make the ShotListener.PCK into actual C++ code: tolua++5.1 -o tolua_shot.cpp -H tolua_shot.h -n ShotListener shotlistener.pkg This created two files tolua_shot.cpp and tolua_shot.h. These i included in my project along with the ShotListener.h file. In the main.cpp i added the following before the app->Start() if (Interpreter::L==NULL) Interpreter::Reset(); tolua_ShotListener_open(Interpreter::L); Hi then had a ton of debugging to avoid segmentation error bugs related to multithreading. But in the end it works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.