Original Post
Hi there, i've just finished up reading the LUA Language documentation. I'm working on a graphic adventure engine, written in C++ and fully OOP (practically no standard c functions right now).
I want to use LUA as the scripting language for the different graphic adventures that might be made with my engine. Currently i have more or less this layout (i'll give you just a rough sight):
A cUtopiaEngine class object, that holds as attributes other subsystems and objects. Here's the interface (sorry about the comments in spanish but it's my native language. The notation and elements names are in english though)
Finally, my question is, since i'm just starting up with LUA, AFAIK i could register C Functions at the host program, that may be called from LUA Scripts. But is it possible, to use the host program objects, directly from LUA Code, without having to wrap each object method via a C Function?
I mean, suppose i want to call the method of the main negine object from LUA Code:
objEngine->mLoadNewRoom(1);
What i would do right now, is have a C Function at the host program, that wrapps that method, and register that to LUA so it can be called. IE:
static int LoadNewRoom(lua_State *L) {
// Get the room ID from the Lua Stack
...
// Call the engine method for loading up a new room
objEngine->mLoadNewRoom(nRoomID);
}
-------------------------------------------------------
Obviously, doing this for every engine method, is not quite efficient, cause i would have a layer of cfunctions wrapping an object methods, and after that layer the whole encapsulation OOP gives. So i would really like to know if LUA can interact directly with C++ Objects somehow. I'll keep reaserching meanwhile.
Thanks in Advance, Bugo //
EDIT: i've just read something about an implementation called TOLUA, which might be the solution for my problem. But i'm still open to advice.
[edited by - Bu6mAn on March 11, 2003 4:23:38 PM]
// ------------------------------------------------------------------------- //
// Interface: Class cUtopiaEngine //
// //
// Descripcion: Main Engine Class //
// //
// Atributos: CL_ResourceManager* aResManager; // Manager para los Resources //
// CL_Slot mousePress; // Slot para el evento Mouse Button Press //
// CL_Slot keyPress; // Slot para el evento Keybord Key Press //
// std::vector<cRoom*> aGameRooms; // Listado de Rooms //
// cRoom* aRoom; // Room actual //
// cPersonaje* aPersonaje; // Objeto Personaje de la AVG //
// int aDesiredAction; // Accion que el usuario eligio en el menu //
// int aGameState; // Estado del juego: ej: IN_GAME, AT_MENU, etc //
// //
// Metodos: cUtopiaEngine(); // Constructor //
// void mLoadNewRoom(int nRoomId); // Carga una nueva Room //
// void mHandleClick(const CL_InputEvent &key); //
// void mHandleKeyPress(const CL_InputEvent &key); //
// void mRun() // Es el main loop que chequea Input,Sound,GameLogic //
// void mUpdateWorld() // Realiza la Logica necesaria segun Status //
// void mDrawWorld() // Blitea todos los gráficos necesarios en su //
// // estado actual. //
// void mWalkTo(int nX, int nY); // Mueve el personaje al destino //
// ------------------------------------------------------------------------- //
class cUtopiaEngine {
private:
CL_ResourceManager* aResManager;
// Input Handling
CL_Slot mousePress;
CL_Slot keyPress;
// Game Objects
std::vector<cRoom*> aGameRooms; // Listado de Rooms
cRoom* aCurrentRoom; // Room Actual
cPersonaje* aPersonaje; // The EGO
cPathSystem* aPathSystem; // Pathfinding System
TiXmlDocument aXMLDoc; // XML Support for resource data
// GameState Crap
int aDesiredAction;
int aGameState;
public:
// Initialization
cUtopiaEngine();
void mLoadNewRoom(int nRoomId);
// Input Handling
void mHandleMouseClick(const CL_InputEvent &key);
void mHandleKeyPress(const CL_InputEvent &key);
// Game Logic
void mRun();
void mUpdateWorld();
void mDrawWorld();
void mWalkTo(int nX, int nY);
};