From 40b8cc7825b2a6f34eec3b03c0c4433c666252aa Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 25 Jun 2018 23:15:30 +0200 Subject: [PATCH] [DEV] try set it work again --- luaWrapper/luaWrapper.hpp | 519 +++++++++--------- .../{luaWrapperStd.cpp => luaWrapperEtk.cpp} | 0 luaWrapper/luaWrapperUtil.hpp | 24 +- lutin_luaWrapper.py | 15 +- sample/example1/lutin_luaWrapperExample1.py | 26 - sample/example2/lutin_luaWrapperExample2.py | 26 - sample/{example1 => sample_1}/BankAccount.cpp | 0 sample/{example1 => sample_1}/BankAccount.hpp | 0 .../{example1 => sample_1}/LuaBankAccount.cpp | 13 +- .../{example1 => sample_1}/LuaBankAccount.hpp | 0 sample/{example1 => sample_1}/Makefile | 0 sample/{example1 => sample_1}/README | 0 sample/{example1 => sample_1}/example1.lua | 0 sample/{example1 => sample_1}/main.cpp | 0 sample/{example2 => sample_2}/Example.cpp | 0 sample/{example2 => sample_2}/Example.hpp | 0 .../{example2 => sample_2}/LuaCustomTypes.hpp | 0 sample/{example2 => sample_2}/LuaExample.cpp | 0 sample/{example2 => sample_2}/LuaExample.hpp | 0 sample/{example2 => sample_2}/Makefile | 0 sample/{example2 => sample_2}/README | 0 sample/{example2 => sample_2}/Vector2D.hpp | 0 sample/{example2 => sample_2}/example2.lua | 0 sample/{example2 => sample_2}/main.cpp | 0 24 files changed, 293 insertions(+), 330 deletions(-) rename luaWrapper/{luaWrapperStd.cpp => luaWrapperEtk.cpp} (100%) delete mode 100644 sample/example1/lutin_luaWrapperExample1.py delete mode 100644 sample/example2/lutin_luaWrapperExample2.py rename sample/{example1 => sample_1}/BankAccount.cpp (100%) rename sample/{example1 => sample_1}/BankAccount.hpp (100%) rename sample/{example1 => sample_1}/LuaBankAccount.cpp (86%) rename sample/{example1 => sample_1}/LuaBankAccount.hpp (100%) rename sample/{example1 => sample_1}/Makefile (100%) rename sample/{example1 => sample_1}/README (100%) rename sample/{example1 => sample_1}/example1.lua (100%) rename sample/{example1 => sample_1}/main.cpp (100%) rename sample/{example2 => sample_2}/Example.cpp (100%) rename sample/{example2 => sample_2}/Example.hpp (100%) rename sample/{example2 => sample_2}/LuaCustomTypes.hpp (100%) rename sample/{example2 => sample_2}/LuaExample.cpp (100%) rename sample/{example2 => sample_2}/LuaExample.hpp (100%) rename sample/{example2 => sample_2}/Makefile (100%) rename sample/{example2 => sample_2}/README (100%) rename sample/{example2 => sample_2}/Vector2D.hpp (100%) rename sample/{example2 => sample_2}/example2.lua (100%) rename sample/{example2 => sample_2}/main.cpp (100%) diff --git a/luaWrapper/luaWrapper.hpp b/luaWrapper/luaWrapper.hpp index 2e114fb..36d7468 100644 --- a/luaWrapper/luaWrapper.hpp +++ b/luaWrapper/luaWrapper.hpp @@ -31,13 +31,12 @@ * * For more information see the README and the comments below */ -#ifndef __LUA_WRAPPER_H__ -#define __LUA_WRAPPER_H__ +#pragma once // If you are linking against Lua compiled in C++, define LUAW_NO_EXTERN_C #include #include -#include +#include #define LUAW_POSTCTOR_KEY "__postctor" #define LUAW_EXTENDS_KEY "__extends" @@ -51,7 +50,7 @@ * Useful for when a parameter index needs to be adjusted * after pushing or popping things off the stack */ -inline int luaW_correctindex(lua_State* _L, int _index, int _correction) { +inline int luaW_correctindex(lua_State* _luaState, int _index, int _correction) { return _index < 0 ? _index - _correction : _index; } @@ -60,8 +59,8 @@ inline int luaW_correctindex(lua_State* _L, int _index, int _correction) { * alternative option, you may select a different function when registering * your class. */ -template std::shared_ptr luaW_defaultallocator(lua_State* _L) { - return std::make_shared(); +template ememory::SharedPtr luaW_defaultallocator(lua_State* _luaState) { + return ememory::makeShared(); } /** @@ -71,8 +70,8 @@ template std::shared_ptr luaW_defaultallocator(lua_State* _L) { * are using shared_ptr you would need to push the address of the object the * shared_ptr represents, rather than the address of the shared_ptr itself. */ -template void luaW_defaultidentifier(lua_State* _L, std::shared_ptr _obj) { - lua_pushlightuserdata(_L, _obj.get()); +template void luaW_defaultidentifier(lua_State* _luaState, ememory::SharedPtr _obj) { + lua_pushlightuserdata(_luaState, _obj.get()); } /** @@ -84,12 +83,26 @@ template void luaW_defaultidentifier(lua_State* _L, std::shared_ptr * when and object is the type I want. This is only used internally. */ struct luaW_Userdata { - luaW_Userdata(std::shared_ptr vptr = NULL, luaW_Userdata (*udcast)(const luaW_Userdata&) = NULL) : - data(vptr), + luaW_Userdata(ememory::SharedPtr vptr = NULL, luaW_Userdata (*udcast)(const luaW_Userdata&) = NULL) : + data(etk::move(vptr)), cast(udcast) { // nothing to do ... } - std::shared_ptr data; + luaW_Userdata(luaW_Userdata&& _obj) { + etk::swap(data, _obj.data); + } + luaW_Userdata(const luaW_Userdata& _obj) { + data = _obj.data; + } + luaW_Userdata& operator= (luaW_Userdata&& _obj) { + etk::swap(data, _obj.data); + return *this; + } + luaW_Userdata& operator= (const luaW_Userdata& _obj) { + data = _obj.data; + return *this; + } + ememory::SharedPtr data; luaW_Userdata (*cast)(const luaW_Userdata&); }; @@ -100,18 +113,18 @@ struct luaW_Userdata { template class LuaWrapper { public: static const char* classname; - static void (*identifier)(lua_State*, std::shared_ptr); - static std::shared_ptr (*allocator)(lua_State*); + static void (*identifier)(lua_State*, ememory::SharedPtr); + static ememory::SharedPtr (*allocator)(lua_State*); static luaW_Userdata (*cast)(const luaW_Userdata&); - static void (*postconstructorrecurse)(lua_State* _L, int numargs); + static void (*postconstructorrecurse)(lua_State* _luaState, int numargs); private: LuaWrapper(); }; template const char* LuaWrapper::classname; -template void (*LuaWrapper::identifier)(lua_State*, std::shared_ptr); -template std::shared_ptr (*LuaWrapper::allocator)(lua_State*); +template void (*LuaWrapper::identifier)(lua_State*, ememory::SharedPtr); +template ememory::SharedPtr (*LuaWrapper::allocator)(lua_State*); template luaW_Userdata (*LuaWrapper::cast)(const luaW_Userdata&); -template void (*LuaWrapper::postconstructorrecurse)(lua_State* _L, int _numargs); +template void (*LuaWrapper::postconstructorrecurse)(lua_State* _luaState, int _numargs); /** * Cast from an object of type T to an object of type U. This template @@ -119,19 +132,19 @@ template void (*LuaWrapper::postconstructorrecurse)(lua_State* _ * internally. */ template luaW_Userdata luaW_cast(const luaW_Userdata& _obj) { - return luaW_Userdata(static_cast(std::static_pointer_cast(_obj.data)), LuaWrapper::cast); + return luaW_Userdata(static_cast(ememory::staticPointerCast(_obj.data)), LuaWrapper::cast); } -template void luaW_identify(lua_State* _L, T* _obj) { - LuaWrapper::identifier(_L, static_cast(_obj)); +template void luaW_identify(lua_State* _luaState, T* _obj) { + LuaWrapper::identifier(_luaState, static_cast(_obj)); } -template inline void luaW_wrapperfield(lua_State* _L, const char* _field) { - lua_getfield(_L, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper - lua_getfield(_L, -1, _field); // ... LuaWrapper LuaWrapper.field - lua_getfield(_L, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.field LuaWrapper.field.class - lua_replace(_L, -3); // ... LuaWrapper.field.class LuaWrapper.field - lua_pop(_L, 1); // ... LuaWrapper.field.class +template inline void luaW_wrapperfield(lua_State* _luaState, const char* _field) { + lua_getfield(_luaState, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper + lua_getfield(_luaState, -1, _field); // ... LuaWrapper LuaWrapper.field + lua_getfield(_luaState, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.field LuaWrapper.field.class + lua_replace(_luaState, -3); // ... LuaWrapper.field.class LuaWrapper.field + lua_pop(_luaState, 1); // ... LuaWrapper.field.class } /** @@ -140,25 +153,25 @@ template inline void luaW_wrapperfield(lua_State* _L, const char* _ * Returns 1 if the value at the given acceptable index is of type T (or if * strict is false, convertable to type T) and 0 otherwise. */ -template bool luaW_is(lua_State *_L, int _index, bool _strict = false) { - bool equal = false;// lua_isnil(_L, index); - if (!equal && lua_isuserdata(_L, _index) && lua_getmetatable(_L, _index)) { +template bool luaW_is(lua_State *_luaState, int _index, bool _strict = false) { + bool equal = false;// lua_isnil(_luaState, index); + if (!equal && lua_isuserdata(_luaState, _index) && lua_getmetatable(_luaState, _index)) { // ... ud ... udmt - luaL_getmetatable(_L, LuaWrapper::classname); // ... ud ... udmt Tmt - equal = lua_rawequal(_L, -1, -2) != 0; + luaL_getmetatable(_luaState, LuaWrapper::classname); // ... ud ... udmt Tmt + equal = lua_rawequal(_luaState, -1, -2) != 0; if (!equal && !_strict) { - lua_getfield(_L, -2, LUAW_EXTENDS_KEY); // ... ud ... udmt Tmt udmt.extends - for (lua_pushnil(_L); lua_next(_L, -2); lua_pop(_L, 1)) { + lua_getfield(_luaState, -2, LUAW_EXTENDS_KEY); // ... ud ... udmt Tmt udmt.extends + for (lua_pushnil(_luaState); lua_next(_luaState, -2); lua_pop(_luaState, 1)) { // ... ud ... udmt Tmt udmt.extends k v - equal = lua_rawequal(_L, -1, -4) != 0; + equal = lua_rawequal(_luaState, -1, -4) != 0; if (equal) { - lua_pop(_L, 2); // ... ud ... udmt Tmt udmt.extends + lua_pop(_luaState, 2); // ... ud ... udmt Tmt udmt.extends break; } } - lua_pop(_L, 1); // ... ud ... udmt Tmt + lua_pop(_luaState, 1); // ... ud ... udmt Tmt } - lua_pop(_L, 2); // ... ud ... + lua_pop(_luaState, 2); // ... ud ... } return equal; } @@ -169,18 +182,18 @@ template bool luaW_is(lua_State *_L, int _index, bool _strict = fal * Converts the given acceptable index to a T*. That value must be of (or * convertable to) type T; otherwise, returns NULL. */ -template std::shared_ptr luaW_to(lua_State* _L, int _index, bool _strict = false) { - if (luaW_is(_L, _index, _strict)) { - luaW_Userdata* pud = static_cast(lua_touserdata(_L, _index)); +template ememory::SharedPtr luaW_to(lua_State* _luaState, int _index, bool _strict = false) { + if (luaW_is(_luaState, _index, _strict)) { + luaW_Userdata* pud = static_cast(lua_touserdata(_luaState, _index)); luaW_Userdata ud; while ( !_strict && LuaWrapper::cast != pud->cast) { ud = pud->cast(*pud); pud = &ud; } - return std::static_pointer_cast(pud->data); + return ememory::staticPointerCast(pud->data); } - return NULL; + return null; } /** @@ -189,28 +202,28 @@ template std::shared_ptr luaW_to(lua_State* _L, int _index, bool * Converts the given acceptable index to a T*. That value must be of (or * convertable to) type T; otherwise, an error is raised. */ -template std::shared_ptr luaW_check(lua_State* _L, int _index, bool _strict = false) { - std::shared_ptr obj; - if (luaW_is(_L, _index, _strict)) { - luaW_Userdata* pud = static_cast(lua_touserdata(_L, _index)); +inline template ememory::SharedPtr luaW_check(lua_State* _luaState, int _index, bool _strict = false) { + ememory::SharedPtr obj; + if (luaW_is(_luaState, _index, _strict)) { + luaW_Userdata* pud = static_cast(lua_touserdata(_luaState, _index)); luaW_Userdata ud; while (!_strict && LuaWrapper::cast != pud->cast) { ud = pud->cast(*pud); pud = &ud; } - obj = std::static_pointer_cast(pud->data); + obj = ememory::staticPointerCast(pud->data); } else { - const char *msg = lua_pushfstring(_L, "%s expected, got %s", LuaWrapper::classname, luaL_typename(_L, _index)); - luaL_argerror(_L, _index, msg); + const char *msg = lua_pushfstring(_luaState, "%s expected, got %s", LuaWrapper::classname, luaL_typename(_luaState, _index)); + luaL_argerror(_luaState, _index, msg); } return obj; } -template std::shared_ptr luaW_opt(lua_State* _L, int _index, std::shared_ptr _fallback = null, bool _strict = false) { - if (lua_isnil(_L, _index)) { +inline template ememory::SharedPtr luaW_opt(lua_State* _luaState, int _index, ememory::SharedPtr _fallback = NULL, bool _strict = false) { + if (lua_isnil(_luaState, _index)) { return _fallback; } else { - return luaW_check(_L, _index, _strict); + return luaW_check(_luaState, _index, _strict); } } @@ -221,31 +234,31 @@ template std::shared_ptr luaW_opt(lua_State* _L, int _index, std * the Lua environment, it will assign the existing storage table to it. * Otherwise, a new storage table will be created for it. */ -template void luaW_push(lua_State* _L, std::shared_ptr _obj) { - if (_obj) { - LuaWrapper::identifier(_L, _obj); // ... id - luaW_wrapperfield(_L, LUAW_CACHE_KEY); // ... id cache - lua_pushvalue(_L, -2); // ... id cache id - lua_gettable(_L, -2); // ... id cache obj - if (lua_isnil(_L, -1)) { +inline template void luaW_push(lua_State* _luaState, ememory::SharedPtr _obj) { + if (_obj != null) { + LuaWrapper::identifier(_luaState, _obj); // ... id + luaW_wrapperfield(_luaState, LUAW_CACHE_KEY); // ... id cache + lua_pushvalue(_luaState, -2); // ... id cache id + lua_gettable(_luaState, -2); // ... id cache obj + if (lua_isnil(_luaState, -1)) { // Create the new luaW_userdata and place it in the cache - lua_pop(_L, 1); // ... id cache - lua_insert(_L, -2); // ... cache id - luaW_Userdata* ud = static_cast(lua_newuserdata(_L, sizeof(luaW_Userdata))); // ... cache id obj + lua_pop(_luaState, 1); // ... id cache + lua_insert(_luaState, -2); // ... cache id + luaW_Userdata* ud = static_cast(lua_newuserdata(_luaState, sizeof(luaW_Userdata))); // ... cache id obj ud->data = _obj; ud->cast = LuaWrapper::cast; - lua_pushvalue(_L, -1); // ... cache id obj obj - lua_insert(_L, -4); // ... obj cache id obj - lua_settable(_L, -3); // ... obj cache - luaL_getmetatable(_L, LuaWrapper::classname); // ... obj cache mt - lua_setmetatable(_L, -3); // ... obj cache - lua_pop(_L, 1); // ... obj + lua_pushvalue(_luaState, -1); // ... cache id obj obj + lua_insert(_luaState, -4); // ... obj cache id obj + lua_settable(_luaState, -3); // ... obj cache + luaL_getmetatable(_luaState, LuaWrapper::classname); // ... obj cache mt + lua_setmetatable(_luaState, -3); // ... obj cache + lua_pop(_luaState, 1); // ... obj } else { - lua_replace(_L, -3); // ... obj cache - lua_pop(_L, 1); // ... obj + lua_replace(_luaState, -3); // ... obj cache + lua_pop(_luaState, 1); // ... obj } } else { - lua_pushnil(_L); + lua_pushnil(_luaState); } } @@ -257,21 +270,21 @@ template void luaW_push(lua_State* _L, std::shared_ptr _obj) { * Returns true if luaW_hold took hold of the object, and false if it was * already held */ -template bool luaW_hold(lua_State* _L, std::shared_ptr _obj) { - luaW_wrapperfield(_L, LUAW_HOLDS_KEY); // ... holds - LuaWrapper::identifier(_L, _obj); // ... holds id - lua_pushvalue(_L, -1); // ... holds id id - lua_gettable(_L, -3); // ... holds id hold +inline template bool luaW_hold(lua_State* _luaState, ememory::SharedPtr _obj) { + luaW_wrapperfield(_luaState, LUAW_HOLDS_KEY); // ... holds + LuaWrapper::identifier(_luaState, _obj); // ... holds id + lua_pushvalue(_luaState, -1); // ... holds id id + lua_gettable(_luaState, -3); // ... holds id hold // If it's not held, hold it - if (!lua_toboolean(_L, -1)) { + if (!lua_toboolean(_luaState, -1)) { // Apply hold boolean - lua_pop(_L, 1); // ... holds id - lua_pushboolean(_L, true); // ... holds id true - lua_settable(_L, -3); // ... holds - lua_pop(_L, 1); // ... + lua_pop(_luaState, 1); // ... holds id + lua_pushboolean(_luaState, true); // ... holds id true + lua_settable(_luaState, -3); // ... holds + lua_pop(_luaState, 1); // ... return true; } - lua_pop(_L, 3); // ... + lua_pop(_luaState, 3); // ... return false; } @@ -285,35 +298,35 @@ template bool luaW_hold(lua_State* _L, std::shared_ptr _obj) { * has already been deallocated. A wrapper is provided for when it is more * convenient to pass in the object directly. */ -template void luaW_release(lua_State* _L, int _index) { - luaW_wrapperfield(_L, LUAW_HOLDS_KEY); // ... id ... holds - lua_pushvalue(_L, luaW_correctindex(_L, _index, 1)); // ... id ... holds id - lua_pushnil(_L); // ... id ... holds id nil - lua_settable(_L, -3); // ... id ... holds - lua_pop(_L, 1); // ... id ... +template void luaW_release(lua_State* _luaState, int _index) { + luaW_wrapperfield(_luaState, LUAW_HOLDS_KEY); // ... id ... holds + lua_pushvalue(_luaState, luaW_correctindex(_luaState, _index, 1)); // ... id ... holds id + lua_pushnil(_luaState); // ... id ... holds id nil + lua_settable(_luaState, -3); // ... id ... holds + lua_pop(_luaState, 1); // ... id ... } -template void luaW_release(lua_State* _L, T* _obj) { - LuaWrapper::identifier(_L, _obj); // ... id - luaW_release(_L, -1); // ... id - lua_pop(_L, 1); // ... +template void luaW_release(lua_State* _luaState, T* _obj) { + LuaWrapper::identifier(_luaState, _obj); // ... id + luaW_release(_luaState, -1); // ... id + lua_pop(_luaState, 1); // ... } -template void luaW_postconstructorinternal(lua_State* _L, int _numargs) { +template void luaW_postconstructorinternal(lua_State* _luaState, int _numargs) { // ... ud args... if (LuaWrapper::postconstructorrecurse) { - LuaWrapper::postconstructorrecurse(_L, _numargs); + LuaWrapper::postconstructorrecurse(_luaState, _numargs); } - luaL_getmetatable(_L, LuaWrapper::classname); // ... ud args... mt - lua_getfield(_L, -1, LUAW_POSTCTOR_KEY); // ... ud args... mt postctor - if (lua_type(_L, -1) == LUA_TFUNCTION) { + luaL_getmetatable(_luaState, LuaWrapper::classname); // ... ud args... mt + lua_getfield(_luaState, -1, LUAW_POSTCTOR_KEY); // ... ud args... mt postctor + if (lua_type(_luaState, -1) == LUA_TFUNCTION) { for (int i = 0; i < _numargs + 1; i++) { - lua_pushvalue(_L, -3 - _numargs); // ... ud args... mt postctor ud args... + lua_pushvalue(_luaState, -3 - _numargs); // ... ud args... mt postctor ud args... } - lua_call(_L, _numargs + 1, 0); // ... ud args... mt - lua_pop(_L, 1); // ... ud args... + lua_call(_luaState, _numargs + 1, 0); // ... ud args... mt + lua_pop(_luaState, 1); // ... ud args... } else { - lua_pop(_L, 2); // ... ud args... + lua_pop(_luaState, 2); // ... ud args... } } @@ -327,10 +340,10 @@ template void luaW_postconstructorinternal(lua_State* _L, int _numa * arguments This exists to allow types to adjust values in thier storage table, * which can not be created until after the constructor is called. */ -template void luaW_postconstructor(lua_State* _L, int _numargs) { +template void luaW_postconstructor(lua_State* _luaState, int _numargs) { // ... ud args... - luaW_postconstructorinternal(_L, _numargs); // ... ud args... - lua_pop(_L, _numargs); // ... ud + luaW_postconstructorinternal(_luaState, _numargs); // ... ud args... + lua_pop(_luaState, _numargs); // ... ud } /** @@ -339,18 +352,18 @@ template void luaW_postconstructor(lua_State* _L, int _numargs) { * Creates an object of type T using the constructor and subsequently calls the * post-constructor on it. */ -template inline int luaW_new(lua_State* _L, int _numargs) { +template inline int luaW_new(lua_State* _luaState, int _numargs) { // ... args... - std::shared_ptr obj = LuaWrapper::allocator(_L); - luaW_push(_L, obj); // ... args... ud - luaW_hold(_L, obj); - lua_insert(_L, -1 - _numargs); // ... ud args... - luaW_postconstructor(_L, _numargs); // ... ud + ememory::SharedPtr obj = LuaWrapper::allocator(_luaState); + luaW_push(_luaState, obj); // ... args... ud + luaW_hold(_luaState, obj); + lua_insert(_luaState, -1 - _numargs); // ... ud args... + luaW_postconstructor(_luaState, _numargs); // ... ud return 1; } -template int luaW_new(lua_State* _L) { - return luaW_new(_L, lua_gettop(_L)); +template int luaW_new(lua_State* _luaState) { + return luaW_new(_luaState, lua_gettop(_luaState)); } /** @@ -362,24 +375,24 @@ template int luaW_new(lua_State* _L) { * individual userdata can be treated as a table, and can hold thier own * values. */ -template int luaW_index(lua_State* _L) { +template int luaW_index(lua_State* _luaState) { // obj key - std::shared_ptr obj = luaW_to(_L, 1); - luaW_wrapperfield(_L, LUAW_STORAGE_KEY); // obj key storage - LuaWrapper::identifier(_L, obj); // obj key storage id - lua_gettable(_L, -2); // obj key storage store + ememory::SharedPtr obj = luaW_to(_luaState, 1); + luaW_wrapperfield(_luaState, LUAW_STORAGE_KEY); // obj key storage + LuaWrapper::identifier(_luaState, obj); // obj key storage id + lua_gettable(_luaState, -2); // obj key storage store // Check if storage table exists - if (!lua_isnil(_L, -1)) { - lua_pushvalue(_L, -3); // obj key storage store key - lua_gettable(_L, -2); // obj key storage store store[k] + if (!lua_isnil(_luaState, -1)) { + lua_pushvalue(_luaState, -3); // obj key storage store key + lua_gettable(_luaState, -2); // obj key storage store store[k] } // If either there is no storage table or the key wasn't found // then fall back to the metatable - if (lua_isnil(_L, -1)) { - lua_settop(_L, 2); // obj key - lua_getmetatable(_L, -2); // obj key mt - lua_pushvalue(_L, -2); // obj key mt k - lua_gettable(_L, -2); // obj key mt mt[k] + if (lua_isnil(_luaState, -1)) { + lua_settop(_luaState, 2); // obj key + lua_getmetatable(_luaState, -2); // obj key mt + lua_pushvalue(_luaState, -2); // obj key mt k + lua_gettable(_luaState, -2); // obj key mt mt[k] } return 1; } @@ -393,24 +406,24 @@ template int luaW_index(lua_State* _L) { * individual userdata can be treated as a table, and can hold thier own * values. */ -template int luaW_newindex(lua_State* _L) { +template int luaW_newindex(lua_State* _luaState) { // obj key value - std::shared_ptr obj = luaW_check(_L, 1); - luaW_wrapperfield(_L, LUAW_STORAGE_KEY); // obj key value storage - LuaWrapper::identifier(_L, obj); // obj key value storage id - lua_pushvalue(_L, -1); // obj key value storage id id - lua_gettable(_L, -3); // obj key value storage id store + ememory::SharedPtr obj = luaW_check(_luaState, 1); + luaW_wrapperfield(_luaState, LUAW_STORAGE_KEY); // obj key value storage + LuaWrapper::identifier(_luaState, obj); // obj key value storage id + lua_pushvalue(_luaState, -1); // obj key value storage id id + lua_gettable(_luaState, -3); // obj key value storage id store // Add the storage table if there isn't one already - if (lua_isnil(_L, -1)) { - lua_pop(_L, 1); // obj key value storage id - lua_newtable(_L); // obj key value storage id store - lua_pushvalue(_L, -1); // obj key value storage id store store - lua_insert(_L, -3); // obj key value storage store id store - lua_settable(_L, -4); // obj key value storage store + if (lua_isnil(_luaState, -1)) { + lua_pop(_luaState, 1); // obj key value storage id + lua_newtable(_luaState); // obj key value storage id store + lua_pushvalue(_luaState, -1); // obj key value storage id store store + lua_insert(_luaState, -3); // obj key value storage store id store + lua_settable(_luaState, -4); // obj key value storage store } - lua_pushvalue(_L, 2); // obj key value ... store key - lua_pushvalue(_L, 3); // obj key value ... store key value - lua_settable(_L, -3); // obj key value ... store + lua_pushvalue(_luaState, 2); // obj key value ... store key + lua_pushvalue(_luaState, 3); // obj key value ... store key value + lua_settable(_luaState, -3); // obj key value ... store return 0; } @@ -421,21 +434,21 @@ template int luaW_newindex(lua_State* _L) { * count is decremented and if this is the final reference to the userdata its * environment table is nil'd and pointer deleted with the destructor callback. */ -template int luaW_gc(lua_State* _L) { +template int luaW_gc(lua_State* _luaState) { // obj - std::shared_ptr obj = luaW_to(_L, 1); - LuaWrapper::identifier(_L, obj); // obj key value storage id - luaW_wrapperfield(_L, LUAW_HOLDS_KEY); // obj id counts count holds - lua_pushvalue(_L, 2); // obj id counts count holds id - lua_gettable(_L, -2); // obj id counts count holds hold - if (lua_toboolean(_L, -1)) { + ememory::SharedPtr obj = luaW_to(_luaState, 1); + LuaWrapper::identifier(_luaState, obj); // obj key value storage id + luaW_wrapperfield(_luaState, LUAW_HOLDS_KEY); // obj id counts count holds + lua_pushvalue(_luaState, 2); // obj id counts count holds id + lua_gettable(_luaState, -2); // obj id counts count holds hold + if (lua_toboolean(_luaState, -1)) { obj.reset(); } - luaW_wrapperfield(_L, LUAW_STORAGE_KEY); // obj id counts count holds hold storage - lua_pushvalue(_L, 2); // obj id counts count holds hold storage id - lua_pushnil(_L); // obj id counts count holds hold storage id nil - lua_settable(_L, -3); // obj id counts count holds hold storage - luaW_release(_L, 2); + luaW_wrapperfield(_luaState, LUAW_STORAGE_KEY); // obj id counts count holds hold storage + lua_pushvalue(_luaState, 2); // obj id counts count holds hold storage id + lua_pushnil(_luaState); // obj id counts count holds hold storage id nil + lua_settable(_luaState, -3); // obj id counts count holds hold storage + luaW_release(_luaState, 2); return 0; } @@ -445,21 +458,21 @@ template int luaW_gc(lua_State* _L) { * * This function is only called from LuaWrapper internally. */ -inline void luaW_registerfuncs(lua_State* _L, const luaL_Reg _defaulttable[], const luaL_Reg _table[]) { +inline void luaW_registerfuncs(lua_State* _luaState, const luaL_Reg _defaulttable[], const luaL_Reg _table[]) { // ... T #if LUA_VERSION_NUM == 502 if (_defaulttable) { - luaL_setfuncs(_L, _defaulttable, 0); // ... T + luaL_setfuncs(_luaState, _defaulttable, 0); // ... T } if (_table) { - luaL_setfuncs(_L, _table, 0); // ... T + luaL_setfuncs(_luaState, _table, 0); // ... T } #else if (_defaulttable) { - luaL_register(_L, NULL, _defaulttable); // ... T + luaL_register(_luaState, NULL, _defaulttable); // ... T } if (_table) { - luaL_register(_L, NULL, _table); // ... T + luaL_register(_luaState, NULL, _table); // ... T } #endif } @@ -469,30 +482,30 @@ inline void luaW_registerfuncs(lua_State* _L, const luaL_Reg _defaulttable[], co * * This function is only called from LuaWrapper internally. */ -inline void luaW_initialize(lua_State* _L) { +inline void luaW_initialize(lua_State* _luaState) { // Ensure that the LuaWrapper table is set up - lua_getfield(_L, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper - if (lua_isnil(_L, -1)) { - lua_newtable(_L); // ... nil {} - lua_pushvalue(_L, -1); // ... nil {} {} - lua_setfield(_L, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... nil LuaWrapper + lua_getfield(_luaState, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper + if (lua_isnil(_luaState, -1)) { + lua_newtable(_luaState); // ... nil {} + lua_pushvalue(_luaState, -1); // ... nil {} {} + lua_setfield(_luaState, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... nil LuaWrapper // Create a storage table - lua_newtable(_L); // ... LuaWrapper nil {} - lua_setfield(_L, -2, LUAW_STORAGE_KEY); // ... nil LuaWrapper + lua_newtable(_luaState); // ... LuaWrapper nil {} + lua_setfield(_luaState, -2, LUAW_STORAGE_KEY); // ... nil LuaWrapper // Create a holds table - lua_newtable(_L); // ... LuaWrapper {} - lua_setfield(_L, -2, LUAW_HOLDS_KEY); // ... nil LuaWrapper + lua_newtable(_luaState); // ... LuaWrapper {} + lua_setfield(_luaState, -2, LUAW_HOLDS_KEY); // ... nil LuaWrapper // Create a cache table, with weak values so that the userdata will not // be ref counted - lua_newtable(_L); // ... nil LuaWrapper {} - lua_setfield(_L, -2, LUAW_CACHE_KEY); // ... nil LuaWrapper - lua_newtable(_L); // ... nil LuaWrapper {} - lua_pushstring(_L, "v"); // ... nil LuaWrapper {} "v" - lua_setfield(_L, -2, "__mode"); // ... nil LuaWrapper {} - lua_setfield(_L, -2, LUAW_CACHE_METATABLE_KEY); // ... nil LuaWrapper - lua_pop(_L, 1); // ... nil + lua_newtable(_luaState); // ... nil LuaWrapper {} + lua_setfield(_luaState, -2, LUAW_CACHE_KEY); // ... nil LuaWrapper + lua_newtable(_luaState); // ... nil LuaWrapper {} + lua_pushstring(_luaState, "v"); // ... nil LuaWrapper {} "v" + lua_setfield(_luaState, -2, "__mode"); // ... nil LuaWrapper {} + lua_setfield(_luaState, -2, LUAW_CACHE_METATABLE_KEY); // ... nil LuaWrapper + lua_pop(_luaState, 1); // ... nil } - lua_pop(_L, 1); // ... + lua_pop(_luaState, 1); // ... } /** @@ -522,13 +535,13 @@ inline void luaW_initialize(lua_State* _L) { * table globally. As with luaL_register and luaL_setfuncs, both funcstions * leave the new table on the top of the stack. */ -template void luaW_setfuncs(lua_State* _L, +template void luaW_setfuncs(lua_State* _luaState, const char* _classname, const luaL_Reg* _table, const luaL_Reg* _metatable, - std::shared_ptr (*_allocator)(lua_State*), - void (*_identifier)(lua_State*, std::shared_ptr)) { - luaW_initialize(_L); + ememory::SharedPtr (*_allocator)(lua_State*), + void (*_identifier)(lua_State*, ememory::SharedPtr)) { + luaW_initialize(_luaState); LuaWrapper::classname = _classname; LuaWrapper::identifier = _identifier; LuaWrapper::allocator = _allocator; @@ -543,73 +556,73 @@ template void luaW_setfuncs(lua_State* _L, { NULL, NULL } }; // Set up per-type tables - lua_getfield(_L, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper - lua_getfield(_L, -1, LUAW_STORAGE_KEY); // ... LuaWrapper LuaWrapper.storage - lua_newtable(_L); // ... LuaWrapper LuaWrapper.storage {} - lua_setfield(_L, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.storage - lua_pop(_L, 1); // ... LuaWrapper - lua_getfield(_L, -1, LUAW_HOLDS_KEY); // ... LuaWrapper LuaWrapper.holds - lua_newtable(_L); // ... LuaWrapper LuaWrapper.holds {} - lua_setfield(_L, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.holds - lua_pop(_L, 1); // ... LuaWrapper - lua_getfield(_L, -1, LUAW_CACHE_KEY); // ... LuaWrapper LuaWrapper.cache - lua_newtable(_L); // ... LuaWrapper LuaWrapper.cache {} - luaW_wrapperfield(_L, LUAW_CACHE_METATABLE_KEY); // ... LuaWrapper LuaWrapper.cache {} cmt - lua_setmetatable(_L, -2); // ... LuaWrapper LuaWrapper.cache {} - lua_setfield(_L, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.cache - lua_pop(_L, 2); // ... + lua_getfield(_luaState, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper + lua_getfield(_luaState, -1, LUAW_STORAGE_KEY); // ... LuaWrapper LuaWrapper.storage + lua_newtable(_luaState); // ... LuaWrapper LuaWrapper.storage {} + lua_setfield(_luaState, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.storage + lua_pop(_luaState, 1); // ... LuaWrapper + lua_getfield(_luaState, -1, LUAW_HOLDS_KEY); // ... LuaWrapper LuaWrapper.holds + lua_newtable(_luaState); // ... LuaWrapper LuaWrapper.holds {} + lua_setfield(_luaState, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.holds + lua_pop(_luaState, 1); // ... LuaWrapper + lua_getfield(_luaState, -1, LUAW_CACHE_KEY); // ... LuaWrapper LuaWrapper.cache + lua_newtable(_luaState); // ... LuaWrapper LuaWrapper.cache {} + luaW_wrapperfield(_luaState, LUAW_CACHE_METATABLE_KEY); // ... LuaWrapper LuaWrapper.cache {} cmt + lua_setmetatable(_luaState, -2); // ... LuaWrapper LuaWrapper.cache {} + lua_setfield(_luaState, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.cache + lua_pop(_luaState, 2); // ... // Open table - lua_newtable(_L); // ... T - luaW_registerfuncs(_L, _allocator ? defaulttable : NULL, _table); // ... T + lua_newtable(_luaState); // ... T + luaW_registerfuncs(_luaState, _allocator ? defaulttable : NULL, _table); // ... T // Open metatable, set up extends table - luaL_newmetatable(_L, _classname); // ... T mt - lua_newtable(_L); // ... T mt {} - lua_setfield(_L, -2, LUAW_EXTENDS_KEY); // ... T mt - luaW_registerfuncs(_L, defaultmetatable, _metatable); // ... T mt - lua_setfield(_L, -2, "metatable"); // ... T + luaL_newmetatable(_luaState, _classname); // ... T mt + lua_newtable(_luaState); // ... T mt {} + lua_setfield(_luaState, -2, LUAW_EXTENDS_KEY); // ... T mt + luaW_registerfuncs(_luaState, defaultmetatable, _metatable); // ... T mt + lua_setfield(_luaState, -2, "metatable"); // ... T } -template void luaW_setfuncs(lua_State* _L, +template void luaW_setfuncs(lua_State* _luaState, const char* _classname, const luaL_Reg* _table, const luaL_Reg* _metatable, - std::shared_ptr (*_allocator)(lua_State*)) { - luaW_setfuncs(_L, _classname, _table, _metatable, _allocator, luaW_defaultidentifier); + ememory::SharedPtr (*_allocator)(lua_State*)) { + luaW_setfuncs(_luaState, _classname, _table, _metatable, _allocator, luaW_defaultidentifier); } -template void luaW_setfuncs(lua_State* _L, +template void luaW_setfuncs(lua_State* _luaState, const char* _classname, const luaL_Reg* _table, const luaL_Reg* _metatable) { - luaW_setfuncs(_L, _classname, _table, _metatable, luaW_defaultallocator, luaW_defaultidentifier); + luaW_setfuncs(_luaState, _classname, _table, _metatable, luaW_defaultallocator, luaW_defaultidentifier); } -template void luaW_register(lua_State* _L, +template void luaW_register(lua_State* _luaState, const char* _classname, const luaL_Reg* _table, const luaL_Reg* _metatable, - std::shared_ptr (*_allocator)(lua_State*), - void (*_identifier)(lua_State*, std::shared_ptr)) { - luaW_setfuncs(_L, _classname, _table, _metatable, _allocator, _identifier); // ... T - lua_pushvalue(_L, -1); // ... T T - lua_setglobal(_L, _classname); // ... T + ememory::SharedPtr (*_allocator)(lua_State*), + void (*_identifier)(lua_State*, ememory::SharedPtr)) { + luaW_setfuncs(_luaState, _classname, _table, _metatable, _allocator, _identifier); // ... T + lua_pushvalue(_luaState, -1); // ... T T + lua_setglobal(_luaState, _classname); // ... T } -template void luaW_register(lua_State* _L, +template void luaW_register(lua_State* _luaState, const char* _classname, const luaL_Reg* _table, const luaL_Reg* _metatable, - std::shared_ptr (*_allocator)(lua_State*)) { - luaW_setfuncs(_L, _classname, _table, _metatable, _allocator, luaW_defaultidentifier); - lua_pushvalue(_L, -1); // ... T T - lua_setglobal(_L, _classname); // ... T + ememory::SharedPtr (*_allocator)(lua_State*)) { + luaW_setfuncs(_luaState, _classname, _table, _metatable, _allocator, luaW_defaultidentifier); + lua_pushvalue(_luaState, -1); // ... T T + lua_setglobal(_luaState, _classname); // ... T } -template void luaW_register(lua_State* _L, +template void luaW_register(lua_State* _luaState, const char* _classname, const luaL_Reg* _table, const luaL_Reg* _metatable) { - luaW_setfuncs(_L, _classname, _table, _metatable, luaW_defaultallocator, luaW_defaultidentifier); // ... T - lua_pushvalue(_L, -1); // ... T T - lua_setglobal(_L, _classname); // ... T + luaW_setfuncs(_luaState, _classname, _table, _metatable, luaW_defaultallocator, luaW_defaultidentifier); // ... T + lua_pushvalue(_luaState, -1); // ... T T + lua_setglobal(_luaState, _classname); // ... T } /** @@ -619,52 +632,50 @@ template void luaW_register(lua_State* _L, * wins). This also allows luaW_to to cast your object apropriately, as * casts straight through a void pointer do not work. */ -template void luaW_extend(lua_State* _L) { +template void luaW_extend(lua_State* _luaState) { if(!LuaWrapper::classname) { - luaL_error(_L, "attempting to call extend on a type that has not been registered"); + luaL_error(_luaState, "attempting to call extend on a type that has not been registered"); } if(!LuaWrapper::classname) { - luaL_error(_L, "attempting to extend %s by a type that has not been registered", LuaWrapper::classname); + luaL_error(_luaState, "attempting to extend %s by a type that has not been registered", LuaWrapper::classname); } LuaWrapper::cast = luaW_cast; LuaWrapper::identifier = luaW_identify; LuaWrapper::postconstructorrecurse = luaW_postconstructorinternal; - luaL_getmetatable(_L, LuaWrapper::classname); // mt - luaL_getmetatable(_L, LuaWrapper::classname); // mt emt + luaL_getmetatable(_luaState, LuaWrapper::classname); // mt + luaL_getmetatable(_luaState, LuaWrapper::classname); // mt emt // Point T's metatable __index at U's metatable for inheritance - lua_newtable(_L); // mt emt {} - lua_pushvalue(_L, -2); // mt emt {} emt - lua_setfield(_L, -2, "__index"); // mt emt {} - lua_setmetatable(_L, -3); // mt emt + lua_newtable(_luaState); // mt emt {} + lua_pushvalue(_luaState, -2); // mt emt {} emt + lua_setfield(_luaState, -2, "__index"); // mt emt {} + lua_setmetatable(_luaState, -3); // mt emt // Set up per-type tables to point at parent type - lua_getfield(_L, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper - lua_getfield(_L, -1, LUAW_STORAGE_KEY); // ... LuaWrapper LuaWrapper.storage - lua_getfield(_L, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.storage U - lua_setfield(_L, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.storage - lua_pop(_L, 1); // ... LuaWrapper - lua_getfield(_L, -1, LUAW_HOLDS_KEY); // ... LuaWrapper LuaWrapper.holds - lua_getfield(_L, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.holds U - lua_setfield(_L, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.holds - lua_pop(_L, 1); // ... LuaWrapper - lua_getfield(_L, -1, LUAW_CACHE_KEY); // ... LuaWrapper LuaWrapper.cache - lua_getfield(_L, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.cache U - lua_setfield(_L, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.cache - lua_pop(_L, 2); // ... + lua_getfield(_luaState, LUA_REGISTRYINDEX, LUAW_WRAPPER_KEY); // ... LuaWrapper + lua_getfield(_luaState, -1, LUAW_STORAGE_KEY); // ... LuaWrapper LuaWrapper.storage + lua_getfield(_luaState, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.storage U + lua_setfield(_luaState, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.storage + lua_pop(_luaState, 1); // ... LuaWrapper + lua_getfield(_luaState, -1, LUAW_HOLDS_KEY); // ... LuaWrapper LuaWrapper.holds + lua_getfield(_luaState, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.holds U + lua_setfield(_luaState, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.holds + lua_pop(_luaState, 1); // ... LuaWrapper + lua_getfield(_luaState, -1, LUAW_CACHE_KEY); // ... LuaWrapper LuaWrapper.cache + lua_getfield(_luaState, -1, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.cache U + lua_setfield(_luaState, -2, LuaWrapper::classname); // ... LuaWrapper LuaWrapper.cache + lua_pop(_luaState, 2); // ... // Make a list of all types that inherit from U, for type checking - lua_getfield(_L, -2, LUAW_EXTENDS_KEY); // mt emt mt.extends - lua_pushvalue(_L, -2); // mt emt mt.extends emt - lua_setfield(_L, -2, LuaWrapper::classname); // mt emt mt.extends - lua_getfield(_L, -2, LUAW_EXTENDS_KEY); // mt emt mt.extends emt.extends - for (lua_pushnil(_L); lua_next(_L, -2); lua_pop(_L, 1)) { + lua_getfield(_luaState, -2, LUAW_EXTENDS_KEY); // mt emt mt.extends + lua_pushvalue(_luaState, -2); // mt emt mt.extends emt + lua_setfield(_luaState, -2, LuaWrapper::classname); // mt emt mt.extends + lua_getfield(_luaState, -2, LUAW_EXTENDS_KEY); // mt emt mt.extends emt.extends + for (lua_pushnil(_luaState); lua_next(_luaState, -2); lua_pop(_luaState, 1)) { // mt emt mt.extends emt.extends k v - lua_pushvalue(_L, -2); // mt emt mt.extends emt.extends k v k - lua_pushvalue(_L, -2); // mt emt mt.extends emt.extends k v k - lua_rawset(_L, -6); // mt emt mt.extends emt.extends k v + lua_pushvalue(_luaState, -2); // mt emt mt.extends emt.extends k v k + lua_pushvalue(_luaState, -2); // mt emt mt.extends emt.extends k v k + lua_rawset(_luaState, -6); // mt emt mt.extends emt.extends k v } - lua_pop(_L, 4); // mt emt + lua_pop(_luaState, 4); // mt emt } -#endif - #include //#include diff --git a/luaWrapper/luaWrapperStd.cpp b/luaWrapper/luaWrapperEtk.cpp similarity index 100% rename from luaWrapper/luaWrapperStd.cpp rename to luaWrapper/luaWrapperEtk.cpp diff --git a/luaWrapper/luaWrapperUtil.hpp b/luaWrapper/luaWrapperUtil.hpp index 0526835..5af142f 100644 --- a/luaWrapper/luaWrapperUtil.hpp +++ b/luaWrapper/luaWrapperUtil.hpp @@ -14,8 +14,7 @@ * This file contains the additional functions that I've added but that do * not really belong in the core API. */ -#ifndef __LUA__WRAPPER__UTILS_HPP__ -#define __LUA__WRAPPER__UTILS_HPP__ +#pragma once #include @@ -624,17 +623,20 @@ template int luaU_build(lua_State* _L) { * } */ template void luaU_store(lua_State* _L, int _index, const char* _storagetable, const char* _key = NULL) { - // ... store ... obj - lua_getfield(_L, _index, _storagetable); // ... store ... obj store.storagetable + // ... store ... obj store.storagetable + lua_getfield(_L, _index, _storagetable); if (_key) { - lua_pushstring(_L, _key); // ... store ... obj store.storagetable key + // ... store ... obj store.storagetable key + lua_pushstring(_L, _key); } else { - LuaWrapper::identifier(_L, luaW_to(_L, -2)); // ... store ... obj store.storagetable key + // ... store ... obj store.storagetable key + LuaWrapper::identifier(_L, luaW_to(_L, -2)); } - lua_pushvalue(_L, -3); // ... store ... obj store.storagetable key obj - lua_settable(_L, -3); // ... store ... obj store.storagetable - lua_pop(_L, 1); // ... store ... obj + // ... store ... obj store.storagetable key obj + lua_pushvalue(_L, -3); + // ... store ... obj store.storagetable + lua_settable(_L, -3); + // ... store ... obj + lua_pop(_L, 1); } - -#endif diff --git a/lutin_luaWrapper.py b/lutin_luaWrapper.py index 7cf4982..ede9a6e 100644 --- a/lutin_luaWrapper.py +++ b/lutin_luaWrapper.py @@ -31,14 +31,17 @@ def get_version(): def configure(target, my_module): my_module.add_extra_flags() - my_module.add_depend('lua') + my_module.add_depend([ + 'lua', + 'ememory' + ]) my_module.add_src_file([ - 'luaWrapper/luaWrapperStd.cpp' - ]) + 'luaWrapper/luaWrapperEtk.cpp', + ]) my_module.add_header_file([ - 'luaWrapper/luaWrapper.hpp' - 'luaWrapper/luaWrapperUtils.hpp' - ]) + 'luaWrapper/luaWrapper.hpp', + 'luaWrapper/luaWrapperUtil.hpp', + ]) return my_module diff --git a/sample/example1/lutin_luaWrapperExample1.py b/sample/example1/lutin_luaWrapperExample1.py deleted file mode 100644 index 985180c..0000000 --- a/sample/example1/lutin_luaWrapperExample1.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python -import lutinModule as module -import lutinTools as tools - -def get_desc(): - return "luaWrapper example 1 : simple lua wrapper" - -def create(target): - # module name is 'edn' and type binary. - myModule = module.Module(__file__, 'luaWrapperExample1', 'BINARY') - # add extra compilation flags : - myModule.add_extra_compile_flags() - # add the file to compile: - myModule.add_src_file([ - 'BankAccount.cpp', - 'LuaBankAccount.cpp', - 'main.cpp']) - - # name of the dependency - myModule.add_module_depend('luaWrapper') - - - # add the currrent module at the - return myModule - - diff --git a/sample/example2/lutin_luaWrapperExample2.py b/sample/example2/lutin_luaWrapperExample2.py deleted file mode 100644 index e5dce73..0000000 --- a/sample/example2/lutin_luaWrapperExample2.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python -import lutinModule as module -import lutinTools as tools - -def get_desc(): - return "luaWrapper example 2 : simple lua wrapper" - -def create(target): - # module name is 'edn' and type binary. - myModule = module.Module(__file__, 'luaWrapperExample2', 'BINARY') - # add extra compilation flags : - myModule.add_extra_compile_flags() - # add the file to compile: - myModule.add_src_file([ - 'Example.cpp', - 'LuaExample.cpp', - 'main.cpp']) - - # name of the dependency - myModule.add_module_depend('luaWrapper') - - - # add the currrent module at the - return myModule - - diff --git a/sample/example1/BankAccount.cpp b/sample/sample_1/BankAccount.cpp similarity index 100% rename from sample/example1/BankAccount.cpp rename to sample/sample_1/BankAccount.cpp diff --git a/sample/example1/BankAccount.hpp b/sample/sample_1/BankAccount.hpp similarity index 100% rename from sample/example1/BankAccount.hpp rename to sample/sample_1/BankAccount.hpp diff --git a/sample/example1/LuaBankAccount.cpp b/sample/sample_1/LuaBankAccount.cpp similarity index 86% rename from sample/example1/LuaBankAccount.cpp rename to sample/sample_1/LuaBankAccount.cpp index 1e656fa..220ad13 100644 --- a/sample/example1/LuaBankAccount.cpp +++ b/sample/sample_1/LuaBankAccount.cpp @@ -15,11 +15,10 @@ using namespace std; * Types that do not have a default contructor require you to write an allocator function. * This function is passed to luaW_register. */ - -BankAccount* BankAccount_new(lua_State *_L) { +ememory::SharedPtr BankAccount_new(lua_State *_L) { const char* owner = luaL_checkstring(_L, 1); float balance = luaL_checknumber(_L, 2); - return new BankAccount(owner, balance); + return ememory::makeShared(owner, balance); } /** @@ -42,27 +41,27 @@ int BankAccount_checkTotalMoneyInBank(lua_State *_L) { */ int BankAccount_getOwnerName(lua_State *_L) { - BankAccount* account = luaW_check(_L, 1); + auto account = luaW_check(_L, 1); lua_pushstring(_L, account->getOwnerName()); return 1; } int BankAccount_deposit(lua_State* _L) { - BankAccount* account = luaW_check(_L, 1); + auto account = luaW_check(_L, 1); float amount = luaL_checknumber(_L, 2); account->deposit(amount); return 0; } int BankAccount_withdraw(lua_State* _L) { - BankAccount* account = luaW_check(_L, 1); + auto account = luaW_check(_L, 1); float amount = luaL_checknumber(_L, 2); account->withdraw(amount); return 0; } int BankAccount_checkBalance(lua_State* _L) { - BankAccount* account = luaW_check(_L, 1); + auto account = luaW_check(_L, 1); lua_pushnumber(_L, account->checkBalance()); return 1; } diff --git a/sample/example1/LuaBankAccount.hpp b/sample/sample_1/LuaBankAccount.hpp similarity index 100% rename from sample/example1/LuaBankAccount.hpp rename to sample/sample_1/LuaBankAccount.hpp diff --git a/sample/example1/Makefile b/sample/sample_1/Makefile similarity index 100% rename from sample/example1/Makefile rename to sample/sample_1/Makefile diff --git a/sample/example1/README b/sample/sample_1/README similarity index 100% rename from sample/example1/README rename to sample/sample_1/README diff --git a/sample/example1/example1.lua b/sample/sample_1/example1.lua similarity index 100% rename from sample/example1/example1.lua rename to sample/sample_1/example1.lua diff --git a/sample/example1/main.cpp b/sample/sample_1/main.cpp similarity index 100% rename from sample/example1/main.cpp rename to sample/sample_1/main.cpp diff --git a/sample/example2/Example.cpp b/sample/sample_2/Example.cpp similarity index 100% rename from sample/example2/Example.cpp rename to sample/sample_2/Example.cpp diff --git a/sample/example2/Example.hpp b/sample/sample_2/Example.hpp similarity index 100% rename from sample/example2/Example.hpp rename to sample/sample_2/Example.hpp diff --git a/sample/example2/LuaCustomTypes.hpp b/sample/sample_2/LuaCustomTypes.hpp similarity index 100% rename from sample/example2/LuaCustomTypes.hpp rename to sample/sample_2/LuaCustomTypes.hpp diff --git a/sample/example2/LuaExample.cpp b/sample/sample_2/LuaExample.cpp similarity index 100% rename from sample/example2/LuaExample.cpp rename to sample/sample_2/LuaExample.cpp diff --git a/sample/example2/LuaExample.hpp b/sample/sample_2/LuaExample.hpp similarity index 100% rename from sample/example2/LuaExample.hpp rename to sample/sample_2/LuaExample.hpp diff --git a/sample/example2/Makefile b/sample/sample_2/Makefile similarity index 100% rename from sample/example2/Makefile rename to sample/sample_2/Makefile diff --git a/sample/example2/README b/sample/sample_2/README similarity index 100% rename from sample/example2/README rename to sample/sample_2/README diff --git a/sample/example2/Vector2D.hpp b/sample/sample_2/Vector2D.hpp similarity index 100% rename from sample/example2/Vector2D.hpp rename to sample/sample_2/Vector2D.hpp diff --git a/sample/example2/example2.lua b/sample/sample_2/example2.lua similarity index 100% rename from sample/example2/example2.lua rename to sample/sample_2/example2.lua diff --git a/sample/example2/main.cpp b/sample/sample_2/main.cpp similarity index 100% rename from sample/example2/main.cpp rename to sample/sample_2/main.cpp