luabridge

Luabridge: Returning C++ lifetime managed object

徘徊边缘 提交于 2019-12-11 11:46:11
问题 This snipped works for basic types: int CreateBasicObject(lua_State *L) { int ret0; lua_pushinteger(L, ret0); return 1; } and in lua it looks like this: local NewObject=CreateBasicObject() How would I go about returning classes instead of ints ? push(L,&MyObject); return 1; does not seem to work correctly, lua portion looks like this: self.MyObject=Screen.MyObject(); And the error is: attempt to index field 'MyObject' (a number value) 回答1: In the newest LuaBridge version you can use

Luabridge binding overloaded operators

心不动则不痛 提交于 2019-12-10 22:14:49
问题 I've written a simple vec3 class, which implements the */+- operators: class vec3 { public: vec3(): x(0.0f),y(0.0f),z(0.0f) {} vec3(float ix, float iy, float iz): x(ix),y(iy),z(iz) {} vec3 operator+(const vec3& v){ vec3 vec(x+v.x,y+v.y,z+v.z); return vec; } vec3 operator-(const vec3& v){ vec3 vec(x-v.x,y-v.y,z-v.z); return vec; } vec3 operator*(const float& s){ vec3 vec(x*s,y*s,z*s); return vec; } vec3 operator/(const float& d){ flot div = 1.0f/d; vec3 vec(x*div,y*div,z*div); return vec; }

Implementing C++ -to-lua observer pattern?

匆匆过客 提交于 2019-12-10 19:54:43
问题 I have an observer (or "listener") pattern implemented in my code as such: struct EntityListener { public: virtual void entityModified(Entity& e) = 0; }; class Entity { public: Entity(); void setListener(EntityListener* listener); private: EntityListener* m_listener; }; Now, this works in C++; the Entity class calls the entityModified() method whenever it needs. Now, I'd like to transfer some of the functionality to Lua, and among those function points is this listener callback. The entities