Original Post
🔒 Locked
Lua OOP question
Advertisement
I have a system set up that is working quite nicely (also using lunar). Lua and C++ can both access objects (complete with non-static member variables and functions).
Here is an example of how I have my classes declared:
I also have to let Lua know about the class by registering it:
With that done, from Lua I can call GameObjectLuaProxy:new() to get a new object in Lua. I can access the object from C++ with the userdata functionality built into the lua C++ API.
Hope this helps ~
Here is an example of how I have my classes declared:
#pragma once#include "lunar.h"class GameObject;class GameObjectManager;class GameObjectLuaProxy{ friend GameObjectManager; friend GameObject; DECLARE_SCRIPT_CLASS(GameObjectLuaProxy);private: GameObject * gameObject; int luaObjectReference;public: GameObjectLuaProxy(lua_State * L); GameObjectLuaProxy(const GameObjectLuaProxy &); ~GameObjectLuaProxy(); const GameObject * getGameObject() const { return gameObject; } int getLuaReference(); SCRIPT_FUNCTION(GetPosition); SCRIPT_FUNCTION(SetPosition); SCRIPT_FUNCTION(GetVelocity); SCRIPT_FUNCTION(SetVelocity); SCRIPT_FUNCTION(ApplyForce); SCRIPT_FUNCTION(SetLook); SCRIPT_FUNCTION(SetColor); SCRIPT_FUNCTION(GetColor); SCRIPT_FUNCTION(SetPhysicsShape); SCRIPT_FUNCTION(SetLabel); SCRIPT_FUNCTION(SetReactive); SCRIPT_FUNCTION(Destroy); SCRIPT_FUNCTION(GetNetworkID);};I also have to let Lua know about the class by registering it:
REGISTER_CLASS(l, GameObjectLuaProxy);With that done, from Lua I can call GameObjectLuaProxy:new() to get a new object in Lua. I can access the object from C++ with the userdata functionality built into the lua C++ API.
Hope this helps ~
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement