[DEV] continue rework
This commit is contained in:
parent
f84ced7d43
commit
fb2e791f08
@ -41,6 +41,7 @@
|
||||
#include <ememory/memory.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
#include <etk/Allocator.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
#include <luaWrapper/debug.hpp>
|
||||
|
||||
@ -73,7 +74,13 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
void executeFile(const etk::String& _fileName) {
|
||||
if (luaL_dofile(m_luaState, _fileName.c_str())) {
|
||||
etk::String data = etk::FSNodeReadAllData(_fileName);
|
||||
if (luaL_dostring(m_luaState, &data[0])) {
|
||||
LUAW_PRINT(lua_tostring(m_luaState, -1));
|
||||
}
|
||||
}
|
||||
void executeString(const etk::String& _rawData) {
|
||||
if (luaL_dostring(m_luaState, &_rawData[0])) {
|
||||
LUAW_PRINT(lua_tostring(m_luaState, -1));
|
||||
}
|
||||
}
|
||||
@ -122,7 +129,7 @@ namespace luaWrapper {
|
||||
* when and object is the type I want. This is only used internally.
|
||||
*/
|
||||
struct Userdata {
|
||||
Userdata(ememory::SharedPtr<void> _vptr = null, size_t _typeId = 0) :
|
||||
Userdata(ememory::SharedPtr<void> _vptr = null, size_t _typeId = 0):
|
||||
m_data(etk::move(_vptr)),
|
||||
m_typeId(_typeId) {
|
||||
// nothing to do ...
|
||||
@ -174,7 +181,7 @@ namespace luaWrapper {
|
||||
}
|
||||
|
||||
template <typename LUAW_TYPE>
|
||||
inline void wrapperfield(lua_State* _luaState, const char* _field) {
|
||||
inline void 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<LUAW_TYPE>::classname); // ... LuaWrapper LuaWrapper.field LuaWrapper.field.class
|
||||
@ -274,7 +281,7 @@ namespace luaWrapper {
|
||||
ememory::SharedPtr<LUAW_TYPE> _obj) {
|
||||
if (_obj != null) {
|
||||
LuaWrapper<LUAW_TYPE>::identifier(_luaState, _obj); // ... id
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_CACHE_KEY); // ... id cache
|
||||
wrapperField<LUAW_TYPE>(_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)) {
|
||||
@ -309,7 +316,7 @@ namespace luaWrapper {
|
||||
template <typename LUAW_TYPE>
|
||||
bool hold(lua_State* _luaState,
|
||||
ememory::SharedPtr<LUAW_TYPE> _obj) {
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_HOLDS_KEY); // ... holds
|
||||
wrapperField<LUAW_TYPE>(_luaState, LUAW_HOLDS_KEY); // ... holds
|
||||
LuaWrapper<LUAW_TYPE>::identifier(_luaState, _obj); // ... holds id
|
||||
lua_pushvalue(_luaState, -1); // ... holds id id
|
||||
lua_gettable(_luaState, -3); // ... holds id hold
|
||||
@ -339,7 +346,7 @@ namespace luaWrapper {
|
||||
template <typename LUAW_TYPE>
|
||||
void release(lua_State* _luaState,
|
||||
int _index) {
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_HOLDS_KEY); // ... id ... holds
|
||||
wrapperField<LUAW_TYPE>(_luaState, LUAW_HOLDS_KEY); // ... id ... holds
|
||||
lua_pushvalue(_luaState, correctindex(_luaState, _index, 1)); // ... id ... holds id
|
||||
lua_pushnil(_luaState); // ... id ... holds id nil
|
||||
lua_settable(_luaState, -3); // ... id ... holds
|
||||
@ -427,7 +434,7 @@ namespace luaWrapper {
|
||||
int index(lua_State* _luaState) {
|
||||
// obj key
|
||||
ememory::SharedPtr<LUAW_TYPE> obj = to<LUAW_TYPE>(_luaState, 1);
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_STORAGE_KEY); // obj key storage
|
||||
wrapperField<LUAW_TYPE>(_luaState, LUAW_STORAGE_KEY); // obj key storage
|
||||
LuaWrapper<LUAW_TYPE>::identifier(_luaState, obj); // obj key storage id
|
||||
lua_gettable(_luaState, -2); // obj key storage store
|
||||
// Check if storage table exists
|
||||
@ -459,7 +466,7 @@ namespace luaWrapper {
|
||||
int newindex(lua_State* _luaState) {
|
||||
// obj key value
|
||||
ememory::SharedPtr<LUAW_TYPE> obj = check<LUAW_TYPE>(_luaState, 1);
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_STORAGE_KEY); // obj key value storage
|
||||
wrapperField<LUAW_TYPE>(_luaState, LUAW_STORAGE_KEY); // obj key value storage
|
||||
LuaWrapper<LUAW_TYPE>::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
|
||||
@ -490,13 +497,13 @@ namespace luaWrapper {
|
||||
/*
|
||||
ememory::SharedPtr<LUAW_TYPE> obj = to<LUAW_TYPE>(_luaState, 1);
|
||||
LuaWrapper<LUAW_TYPE>::identifier(_luaState, obj); // obj key value storage id
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_HOLDS_KEY); // obj id counts count holds
|
||||
wrapperField<LUAW_TYPE>(_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();
|
||||
}
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_STORAGE_KEY); // obj id counts count holds hold storage
|
||||
wrapperField<LUAW_TYPE>(_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
|
||||
@ -630,7 +637,7 @@ namespace luaWrapper {
|
||||
lua_pop(_luaState, 1); // ... LuaWrapper
|
||||
lua_getfield(_luaState, -1, LUAW_CACHE_KEY); // ... LuaWrapper LuaWrapper.cache
|
||||
lua_newtable(_luaState); // ... LuaWrapper LuaWrapper.cache {}
|
||||
wrapperfield<LUAW_TYPE>(_luaState, LUAW_CACHE_METATABLE_KEY); // ... LuaWrapper LuaWrapper.cache {} cmt
|
||||
wrapperField<LUAW_TYPE>(_luaState, LUAW_CACHE_METATABLE_KEY); // ... LuaWrapper LuaWrapper.cache {} cmt
|
||||
lua_setmetatable(_luaState, -2); // ... LuaWrapper LuaWrapper.cache {}
|
||||
lua_setfield(_luaState, -2, LuaWrapper<LUAW_TYPE>::classname); // ... LuaWrapper LuaWrapper.cache
|
||||
lua_pop(_luaState, 2); // ...
|
||||
@ -646,27 +653,27 @@ namespace luaWrapper {
|
||||
}
|
||||
template <typename LUAW_TYPE>
|
||||
void setfuncs(lua_State* _luaState,
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable,
|
||||
ememory::SharedPtr<LUAW_TYPE> (*_allocator)(lua_State*)) {
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable,
|
||||
ememory::SharedPtr<LUAW_TYPE> (*_allocator)(lua_State*)) {
|
||||
setfuncs(_luaState, _classname, _table, _metatable, _allocator, defaultidentifier<LUAW_TYPE>);
|
||||
}
|
||||
template <typename LUAW_TYPE>
|
||||
void setfuncs(lua_State* _luaState,
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable) {
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable) {
|
||||
setfuncs(_luaState, _classname, _table, _metatable, defaultallocator<LUAW_TYPE>, defaultidentifier<LUAW_TYPE>);
|
||||
}
|
||||
|
||||
template <typename LUAW_TYPE>
|
||||
void registerElement(lua_State* _luaState,
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable,
|
||||
ememory::SharedPtr<LUAW_TYPE> (*_allocator)(lua_State*),
|
||||
void (*_identifier)(lua_State*, ememory::SharedPtr<LUAW_TYPE>)) {
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable,
|
||||
ememory::SharedPtr<LUAW_TYPE> (*_allocator)(lua_State*),
|
||||
void (*_identifier)(lua_State*, ememory::SharedPtr<LUAW_TYPE>)) {
|
||||
setfuncs(_luaState, _classname, _table, _metatable, _allocator, _identifier); // ... T
|
||||
lua_pushvalue(_luaState, -1); // ... LUAW_TYPE LUAW_TYPE
|
||||
lua_setglobal(_luaState, _classname); // ... LUAW_TYPE
|
||||
@ -674,10 +681,10 @@ namespace luaWrapper {
|
||||
|
||||
template <typename LUAW_TYPE>
|
||||
void registerElement(lua_State* _luaState,
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable,
|
||||
ememory::SharedPtr<LUAW_TYPE> (*_allocator)(lua_State*)) {
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable,
|
||||
ememory::SharedPtr<LUAW_TYPE> (*_allocator)(lua_State*)) {
|
||||
setfuncs(_luaState, _classname, _table, _metatable, _allocator, defaultidentifier<LUAW_TYPE>);
|
||||
lua_pushvalue(_luaState, -1); // ... LUAW_TYPE LUAW_TYPE
|
||||
lua_setglobal(_luaState, _classname); // ... LUAW_TYPE
|
||||
@ -685,9 +692,9 @@ namespace luaWrapper {
|
||||
|
||||
template <typename LUAW_TYPE>
|
||||
void registerElement(lua_State* _luaState,
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable) {
|
||||
const char* _classname,
|
||||
const luaL_Reg* _table,
|
||||
const luaL_Reg* _metatable) {
|
||||
setfuncs(_luaState, _classname, _table, _metatable, defaultallocator<LUAW_TYPE>, defaultidentifier<LUAW_TYPE>); // ... T
|
||||
lua_pushvalue(_luaState, -1); // ... T T
|
||||
lua_setglobal(_luaState, _classname); // ... T
|
||||
|
@ -107,7 +107,7 @@ namespace luaWrapper {
|
||||
* object through a getter or setter
|
||||
*
|
||||
* The interface to all of them is the same however. In addition to plain
|
||||
* getter and setter functions, there is a getset which does both - if an
|
||||
* getter and setter functions, there is a getSet which does both - if an
|
||||
* argument is supplied it attempts to set the value, and in either case it
|
||||
* returns the value. In your lua table declaration in C++ rather than write
|
||||
* individiual wrappers for each getter and setter you may do the following:
|
||||
@ -116,7 +116,7 @@ namespace luaWrapper {
|
||||
* {
|
||||
* { "GetBar", luaWrapper::utils::get<Foo, bool, &Widget::GetBar> },
|
||||
* { "SetBar", luaWrapper::utils::set<Foo, bool, &Widget::SetBar> },
|
||||
* { "Bar", luaWrapper::utils::getset<Foo, bool, &Widget::GetBar, &Widget::SetBar> },
|
||||
* { "Bar", luaWrapper::utils::getSet<Foo, bool, &Widget::GetBar, &Widget::SetBar> },
|
||||
* { NULL, NULL }
|
||||
* }
|
||||
*
|
||||
@ -135,7 +135,7 @@ namespace luaWrapper {
|
||||
* {
|
||||
* { "GetBar", luaWrapper::utils::get<Foo, bool, &Widget::bar> },
|
||||
* { "SetBar", luaWrapper::utils::set<Foo, bool, &Widget::bar> },
|
||||
* { "Bar", luaWrapper::utils::getset<Foo, bool, &Widget::bar> },
|
||||
* { "Bar", luaWrapper::utils::getSet<Foo, bool, &Widget::bar> },
|
||||
* }
|
||||
*
|
||||
* In a Lua script, you can now use foo:GetBar(), foo:SetBar() and foo:Bar()
|
||||
@ -197,7 +197,7 @@ namespace luaWrapper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T, typename U, const U* T::*Member> int setandrelease(lua_State* _L) {
|
||||
template <typename T, typename U, const U* T::*Member> int setAndRelease(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if (obj != null) {
|
||||
ememory::SharedPtr<U> member = luaWrapper::opt<U>(_L, 2);
|
||||
@ -234,7 +234,7 @@ namespace luaWrapper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T, typename U, void (T::*Setter)(U*)> int setandrelease(lua_State* _L) {
|
||||
template <typename T, typename U, void (T::*Setter)(U*)> int setAndRelease(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if (obj != null) {
|
||||
ememory::SharedPtr<U> member = luaWrapper::opt<U>(_L, 2);
|
||||
@ -246,7 +246,7 @@ namespace luaWrapper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T, typename U, U T::*Member> int getset(lua_State* _L) {
|
||||
template <typename T, typename U, U T::*Member> int getSet(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -258,7 +258,7 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U, U* T::*Member> int getset(lua_State* _L) {
|
||||
template <typename T, typename U, U* T::*Member> int getSet(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -271,7 +271,7 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U, U* T::*Member> int getsetandrelease(lua_State* _L) {
|
||||
template <typename T, typename U, U* T::*Member> int getSetAndRelease(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -286,7 +286,7 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U, U (T::*Getter)() const, void (T::*Setter)(U)> int getset(lua_State* _L) {
|
||||
template <typename T, typename U, U (T::*Getter)() const, void (T::*Setter)(U)> int getSet(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -298,7 +298,7 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U, U (T::*Getter)() const, void (T::*Setter)(const U&)> int getset(lua_State* _L) {
|
||||
template <typename T, typename U, U (T::*Getter)() const, void (T::*Setter)(const U&)> int getSet(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -310,7 +310,7 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U, const U& (T::*Getter)() const, void (T::*Setter)(const U&)> int getset(lua_State* _L) {
|
||||
template <typename T, typename U, const U& (T::*Getter)() const, void (T::*Setter)(const U&)> int getSet(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -322,7 +322,7 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U, U* (T::*Getter)() const, void (T::*Setter)(U*)> int getset(lua_State* _L) {
|
||||
template <typename T, typename U, U* (T::*Getter)() const, void (T::*Setter)(U*)> int getSet(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -335,7 +335,7 @@ namespace luaWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U, U* (T::*Getter)() const, void (T::*Setter)(U*)> int getsetandrelease(lua_State* _L) {
|
||||
template <typename T, typename U, U* (T::*Getter)() const, void (T::*Setter)(U*)> int getSetAndRelease(lua_State* _L) {
|
||||
ememory::SharedPtr<T> obj = luaWrapper::check<T>(_L, 1);
|
||||
if ( obj != null
|
||||
&& lua_gettop(_L) >= 2) {
|
||||
@ -359,12 +359,12 @@ namespace luaWrapper {
|
||||
*
|
||||
* struct Foo
|
||||
* {
|
||||
* int DoSomething(int, const char*);
|
||||
* int doSomething(int, const char*);
|
||||
* };
|
||||
*
|
||||
* static luaL_reg Foo_metatable[] =
|
||||
* {
|
||||
* { "DoSomething", luaWrapper::utils::func(&Foo::DoSomething) },
|
||||
* { "doSomething", luaWrapper::utils::func(&Foo::doSomething) },
|
||||
* { NULL, NULL }
|
||||
* }
|
||||
*
|
||||
@ -376,7 +376,7 @@ namespace luaWrapper {
|
||||
* This macro will expand based on the function signature of Foo::DoSomething
|
||||
* In this example, it would expand into the following wrapper:
|
||||
*
|
||||
* luaWrapper::utils::push(luaWrapper::check<T>(L, 1)->DoSomething(luaWrapper::utils::check<int>(L, 2), luaWrapper::utils::check<const char*>(L, 3)));
|
||||
* luaWrapper::utils::push(luaWrapper::check<T>(L, 1)->doSomething(luaWrapper::utils::check<int>(L, 2), luaWrapper::utils::check<const char*>(L, 3)));
|
||||
* return 1;
|
||||
*
|
||||
* In this example there is only one member function called DoSomething. In some
|
||||
@ -457,27 +457,31 @@ namespace luaWrapper {
|
||||
/**
|
||||
* Member function wrapper
|
||||
*/
|
||||
template<class MemFunPtrType, MemFunPtrType MemberFunc> struct MemberFuncWrapper;
|
||||
template<class LUAW_MEMORY_FUNCTION_POINTER_TYPE, LUAW_MEMORY_FUNCTION_POINTER_TYPE MemberFunc>
|
||||
struct MemberFuncWrapper;
|
||||
|
||||
template<class T, class ReturnType, class... Args, ReturnType(T::*MemberFunc)(Args...)> struct MemberFuncWrapper<ReturnType (T::*)(Args...), MemberFunc> {
|
||||
template<class LUAW_TYPE, class ReturnType, class... Args, ReturnType(LUAW_TYPE::*MemberFunc)(Args...)>
|
||||
struct MemberFuncWrapper<ReturnType (T::*)(Args...), MemberFunc> {
|
||||
public:
|
||||
static int call(lua_State* _L) {
|
||||
return callImpl(_L, makeIntRange<2,sizeof...(Args)>());
|
||||
}
|
||||
private:
|
||||
template<int... indices> static int callImpl(lua_State* _L, IntPack<indices...>) {
|
||||
luaWrapper::utils::push<ReturnType>(_L, ((*luaWrapper::check<T>(_L, 1)).*MemberFunc)(luaWrapper::utils::check<typename luaWrapper::utils::remove_cr<Args>::type>(_L, indices)...));
|
||||
luaWrapper::utils::push<ReturnType>(_L, ((*luaWrapper::check<LUAW_TYPE>(_L, 1)).*MemberFunc)(luaWrapper::utils::check<typename luaWrapper::utils::remove_cr<Args>::type>(_L, indices)...));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class... Args, void(T::*MemberFunc)(Args...)> struct MemberFuncWrapper<void(T::*)(Args...), MemberFunc> {
|
||||
template<class LUAW_TYPE, class... Args, void(LUAW_TYPE::*MemberFunc)(Args...)>
|
||||
struct MemberFuncWrapper<void(T::*)(Args...), MemberFunc> {
|
||||
public:
|
||||
static int call(lua_State* _L) {
|
||||
return callImpl(_L, luaWrapper::utils::makeIntRange<2, sizeof...(Args)>());
|
||||
}
|
||||
private:
|
||||
template<int... indices> static int callImpl(lua_State* _L, IntPack<indices...>) {
|
||||
template<int... indices>
|
||||
static int callImpl(lua_State* _L, IntPack<indices...>) {
|
||||
((*luaWrapper::check<T>(_L, 1)).*MemberFunc)(luaWrapper::utils::check<typename luaWrapper::utils::remove_cr<Args>::type>(_L, indices)...);
|
||||
return 0;
|
||||
}
|
||||
@ -488,21 +492,24 @@ namespace luaWrapper {
|
||||
* static function wrapper
|
||||
*/
|
||||
|
||||
template<class FunPtrType, FunPtrType Func> struct StaticFuncWrapper;
|
||||
template<class LUAW_FUNCTION_POINTER_TYPE, LUAW_FUNCTION_POINTER_TYPE LUAW_FUNCTION>
|
||||
struct StaticFuncWrapper;
|
||||
|
||||
template<class ReturnType, class... Args, ReturnType(*Func)(Args...)> struct StaticFuncWrapper<ReturnType(*)(Args...), Func> {
|
||||
template<class ReturnType, class... Args, ReturnType(*LUAW_FUNCTION)(Args...)>
|
||||
struct StaticFuncWrapper<ReturnType(*)(Args...), LUAW_FUNCTION> {
|
||||
public:
|
||||
static int call(lua_State* _L) {
|
||||
return callImpl(_L, luaWrapper::utils::makeIntRange<2,sizeof...(Args)>());
|
||||
}
|
||||
private:
|
||||
template<int... indices> static int callImpl(lua_State* _L, IntPack<indices...>) {
|
||||
luaWrapper::utils::push<ReturnType>(_L, (*Func)(luaWrapper::utils::check<typename luaWrapper::utils::remove_cr<Args>::type>(_L, indices)...));
|
||||
luaWrapper::utils::push<ReturnType>(_L, (*LUAW_FUNCTION)(luaWrapper::utils::check<typename luaWrapper::utils::remove_cr<Args>::type>(_L, indices)...));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<class... Args, void(*Func)(Args...)> struct StaticFuncWrapper<void(*)(Args...), Func> {
|
||||
template<class... Args, void(*LUAW_FUNCTION)(Args...)>
|
||||
struct StaticFuncWrapper<void(*)(Args...), LUAW_FUNCTION> {
|
||||
public:
|
||||
static int call(lua_State* _L) {
|
||||
return callImpl(_L, luaWrapper::utils::makeIntRange<2, sizeof...(Args)>());
|
||||
@ -510,7 +517,7 @@ namespace luaWrapper {
|
||||
private:
|
||||
template<int... indices>
|
||||
static int callImpl(lua_State* _L, luaWrapper::utils::IntPack<indices...>) {
|
||||
(*Func)(luaWrapper::utils::check<typename luaWrapper::utils::remove_cr<Args>::type>(_L, indices)...);
|
||||
(*LUAW_FUNCTION)(luaWrapper::utils::check<typename luaWrapper::utils::remove_cr<Args>::type>(_L, indices)...);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@ -532,13 +539,13 @@ namespace luaWrapper {
|
||||
* foo = Foo.new()
|
||||
* foo2 = foo:clone()
|
||||
*/
|
||||
template <typename T> int clone(lua_State* _L) {
|
||||
T* obj = new T(*luaWrapper::check<T>(_L, 1));
|
||||
template <typename LUAW_TYPE> int clone(lua_State* _L) {
|
||||
T* obj = new T(*luaWrapper::check<LUAW_TYPE>(_L, 1));
|
||||
lua_remove(_L, 1); // ...
|
||||
int numargs = lua_gettop(_L);
|
||||
luaWrapper::push<T>(_L, obj); // ... clone
|
||||
luaWrapper::hold<T>(_L, obj);
|
||||
luaWrapper::postconstructor<T>(_L, numargs);
|
||||
luaWrapper::postconstructor<LUAW_TYPE>(_L, numargs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -560,7 +567,7 @@ namespace luaWrapper {
|
||||
* After the object is constructed, luaWrapper::utils::build will do the equivalent of
|
||||
* calling f:X(10) and f:Y(20).
|
||||
*/
|
||||
template <typename T> int build(lua_State* _L) {
|
||||
template <typename LUAW_TYPE> int build(lua_State* _L) {
|
||||
// obj {}
|
||||
lua_insert(_L, -2); // {} obj
|
||||
if (lua_type(_L, 1) == LUA_TTABLE) {
|
||||
|
@ -18,9 +18,9 @@ ETK_DECLARE_TYPE(BankAccount);
|
||||
* This function is passed to luaWrapper::register.
|
||||
*/
|
||||
ememory::SharedPtr<BankAccount> BankAccount_new(lua_State *_luaState) {
|
||||
const char* owner = luaL_checkstring(_luaState, 1);
|
||||
float balance = luaL_checknumber(_luaState, 2);
|
||||
return ememory::makeShared<BankAccount>(owner, balance);
|
||||
const char* owner = luaL_checkstring(_luaState, 1);
|
||||
float balance = luaL_checknumber(_luaState, 2);
|
||||
return ememory::makeShared<BankAccount>(owner, balance);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,8 +30,8 @@ ememory::SharedPtr<BankAccount> BankAccount_new(lua_State *_luaState) {
|
||||
*/
|
||||
|
||||
int BankAccount_checkTotalMoneyInBank(lua_State *_luaState) {
|
||||
lua_pushnumber(_luaState, BankAccount::checkTotalMoneyInBank());
|
||||
return 1;
|
||||
lua_pushnumber(_luaState, BankAccount::checkTotalMoneyInBank());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,52 +43,50 @@ int BankAccount_checkTotalMoneyInBank(lua_State *_luaState) {
|
||||
*/
|
||||
|
||||
int BankAccount_getOwnerName(lua_State *_luaState) {
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
lua_pushstring(_luaState, account->getOwnerName());
|
||||
return 1;
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
lua_pushstring(_luaState, account->getOwnerName());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BankAccount_deposit(lua_State* _luaState) {
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
float amount = luaL_checknumber(_luaState, 2);
|
||||
account->deposit(amount);
|
||||
return 0;
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
float amount = luaL_checknumber(_luaState, 2);
|
||||
account->deposit(amount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BankAccount_withdraw(lua_State* _luaState) {
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
float amount = luaL_checknumber(_luaState, 2);
|
||||
account->withdraw(amount);
|
||||
return 0;
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
float amount = luaL_checknumber(_luaState, 2);
|
||||
account->withdraw(amount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BankAccount_checkBalance(lua_State* _luaState) {
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
lua_pushnumber(_luaState, account->checkBalance());
|
||||
return 1;
|
||||
auto account = luaWrapper::check<BankAccount>(_luaState, 1);
|
||||
lua_pushnumber(_luaState, account->checkBalance());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static luaL_Reg BankAccount_table[] = {
|
||||
{ "checkTotalMoneyInBank", BankAccount_checkTotalMoneyInBank },
|
||||
{ NULL, NULL }
|
||||
{ "checkTotalMoneyInBank", BankAccount_checkTotalMoneyInBank },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static luaL_Reg BankAccount_metatable[] = {
|
||||
{ "getOwnerName", BankAccount_getOwnerName },
|
||||
{ "deposit", BankAccount_deposit },
|
||||
{ "withdraw", BankAccount_withdraw },
|
||||
{ "checkBalance", BankAccount_checkBalance },
|
||||
{ NULL, NULL }
|
||||
{ "getOwnerName", BankAccount_getOwnerName },
|
||||
{ "deposit", BankAccount_deposit },
|
||||
{ "withdraw", BankAccount_withdraw },
|
||||
{ "checkBalance", BankAccount_checkBalance },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_BankAccount(lua_State* _luaState) {
|
||||
luaWrapper::registerElement<BankAccount>(_luaState,
|
||||
"BankAccount",
|
||||
BankAccount_table,
|
||||
BankAccount_metatable,
|
||||
BankAccount_new // If your class has a default constructor you can omit this argument,
|
||||
// LuaWrapper will generate a default allocator for you.
|
||||
);
|
||||
return 1;
|
||||
int luaopen_BankAccount(luaWrapper:Lua& _lua) {
|
||||
_lua.registerElement<BankAccount>("BankAccount",
|
||||
BankAccount_table,
|
||||
BankAccount_metatable,
|
||||
BankAccount_new // If your class has a default constructor you can omit this argument, LuaWrapper will generate a default allocator for you.
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
struct lua_State;
|
||||
int luaopen_BankAccount(lua_State* _luaState);
|
||||
int luaopen_BankAccount(luaWrapper:Lua& _lua);
|
||||
|
@ -26,12 +26,12 @@ int main(int _argc, const char *_argv[]) {
|
||||
}
|
||||
}
|
||||
if (inputFileName.empty() == true) {
|
||||
TEST_ERROR("missing file...");
|
||||
usage();
|
||||
TEST_WARNING("missing file... ==> select default one");
|
||||
inputFileName = "DATA:example1.lua";
|
||||
}
|
||||
{
|
||||
luaWrapper::Lua lua;
|
||||
luaopen_BankAccount(lua.getState());
|
||||
luaopen_BankAccount(lua);
|
||||
lua.executeFile(inputFileName);
|
||||
}
|
||||
TEST_PRINT("END SAMPLE 1");
|
||||
|
@ -2,96 +2,97 @@
|
||||
#include <etk/String.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
#include <iostream>
|
||||
#include <test-debug/debug.hpp>
|
||||
|
||||
ETK_DECLARE_TYPE(Example);
|
||||
|
||||
// These are just a bunch of generic getters and setters for
|
||||
// values in the Example class
|
||||
|
||||
bool Example::GetBoolean() const {
|
||||
bool Example::getBoolean() const {
|
||||
return m_boolean;
|
||||
}
|
||||
|
||||
int Example::GetInteger() const {
|
||||
int Example::getInteger() const {
|
||||
return m_integer;
|
||||
}
|
||||
|
||||
unsigned int Example::GetUInteger() const {
|
||||
unsigned int Example::getUInteger() const {
|
||||
return m_uinteger;
|
||||
}
|
||||
|
||||
const char* Example::GetCString() const {
|
||||
const char* Example::getCString() const {
|
||||
return m_cstring;
|
||||
}
|
||||
|
||||
const etk::String& Example::GetCPPString() const {
|
||||
const etk::String& Example::getCPPString() const {
|
||||
return m_cppstring;
|
||||
}
|
||||
|
||||
const Vector2D& Example::GetVec() const {
|
||||
const Vector2D& Example::getVec() const {
|
||||
return m_vec;
|
||||
}
|
||||
|
||||
double Example::GetNumber() const {
|
||||
double Example::getNumber() const {
|
||||
return m_number;
|
||||
}
|
||||
|
||||
float Example::GetFloatNumber() const {
|
||||
float Example::getFloatNumber() const {
|
||||
return m_floatnumber;
|
||||
}
|
||||
|
||||
Example* Example::GetPtr() const {
|
||||
Example* Example::getPtr() const {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
void Example::SetBoolean(bool _val) {
|
||||
void Example::setBoolean(bool _val) {
|
||||
m_boolean = _val;
|
||||
}
|
||||
|
||||
void Example::SetInteger(int _val) {
|
||||
void Example::setInteger(int _val) {
|
||||
m_integer = _val;
|
||||
}
|
||||
|
||||
void Example::SetUInteger(unsigned int _val) {
|
||||
void Example::setUInteger(unsigned int _val) {
|
||||
m_uinteger = _val;
|
||||
}
|
||||
|
||||
void Example::SetCString(const char* _val) {
|
||||
void Example::setCString(const char* _val) {
|
||||
m_cstring = _val;
|
||||
}
|
||||
|
||||
void Example::SetCPPString(const etk::String& _val) {
|
||||
void Example::setCPPString(const etk::String& _val) {
|
||||
m_cppstring = _val;
|
||||
}
|
||||
|
||||
void Example::SetVec(const Vector2D& _val) {
|
||||
void Example::setVec(const Vector2D& _val) {
|
||||
m_vec = _val;
|
||||
}
|
||||
|
||||
void Example::SetNumber(double _val) {
|
||||
void Example::setNumber(double _val) {
|
||||
m_number = _val;
|
||||
}
|
||||
|
||||
void Example::SetFloatNumber(float _val) {
|
||||
void Example::setFloatNumber(float _val) {
|
||||
m_floatnumber = _val;
|
||||
}
|
||||
|
||||
void Example::SetPtr(Example* _val) {
|
||||
void Example::setPtr(Example* _val) {
|
||||
m_ptr = _val;
|
||||
}
|
||||
|
||||
int Example::DoSomething(bool _b) {
|
||||
std::cout << "b = " << _b << std::endl;
|
||||
TEST_PRINT("b = " << _b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Example::DoSomethingElse(int _i, int _j) {
|
||||
std::cout << "i = " << _i << ", j = " << _j << std::endl;
|
||||
TEST_PRINT("i = " << _i << ", j = " << _j);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Example::DoSomethingElse(float _f) {
|
||||
std::cout << "f = " << _f << std::endl;
|
||||
TEST_PRINT("f = " << _f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -18,25 +18,32 @@ class Example {
|
||||
Example* m_ptr = null;
|
||||
Vector2D m_vec = Vector2D(4,6);
|
||||
|
||||
bool GetBoolean() const;
|
||||
int GetInteger() const;
|
||||
unsigned int GetUInteger() const;
|
||||
const char* GetCString() const;
|
||||
const etk::String& GetCPPString() const;
|
||||
double GetNumber() const;
|
||||
float GetFloatNumber() const;
|
||||
Example* GetPtr() const;
|
||||
const Vector2D& GetVec() const;
|
||||
bool getBoolean() const;
|
||||
void setBoolean(bool _val);
|
||||
|
||||
void SetBoolean(bool _val);
|
||||
void SetInteger(int _val);
|
||||
void SetUInteger(unsigned int _val);
|
||||
void SetCString(const char* _val);
|
||||
void SetCPPString(const etk::String& _val);
|
||||
void SetNumber(double _val);
|
||||
void SetFloatNumber(float _val);
|
||||
void SetPtr(Example* _val);
|
||||
void SetVec(const Vector2D& _Member);
|
||||
int getInteger() const;
|
||||
void setInteger(int _val);
|
||||
|
||||
unsigned int getUInteger() const;
|
||||
void setUInteger(unsigned int _val);
|
||||
|
||||
const char* getCString() const;
|
||||
void setCString(const char* _val);
|
||||
|
||||
const etk::String& getCPPString() const;
|
||||
void setCPPString(const etk::String& _val);
|
||||
|
||||
double getNumber() const;
|
||||
void setNumber(double _val);
|
||||
|
||||
float getFloatNumber() const;
|
||||
void setFloatNumber(float _val);
|
||||
|
||||
Example* getPtr() const;
|
||||
void setPtr(Example* _val);
|
||||
|
||||
const Vector2D& getVec() const;
|
||||
void setVec(const Vector2D& _Member);
|
||||
|
||||
int DoSomething(bool _b);
|
||||
void DoSomething2(bool _b, int _p) {};
|
||||
|
@ -38,43 +38,43 @@ static luaL_Reg Example_metatable[] = {
|
||||
// Class | data type | class member
|
||||
{ "getBoolean", luaWrapper::utils::get<Example, bool, &Example::m_boolean> },
|
||||
{ "setBoolean", luaWrapper::utils::set<Example, bool, &Example::m_boolean> },
|
||||
{ "m_boolean", luaWrapper::utils::getset<Example, bool, &Example::m_boolean> },
|
||||
{ "m_boolean", luaWrapper::utils::getSet<Example, bool, &Example::m_boolean> },
|
||||
|
||||
{ "getInteger", luaWrapper::utils::get<Example, int, &Example::m_integer> },
|
||||
{ "setInteger", luaWrapper::utils::set<Example, int, &Example::m_integer> },
|
||||
{ "m_integer", luaWrapper::utils::getset<Example, int, &Example::m_integer> },
|
||||
{ "m_integer", luaWrapper::utils::getSet<Example, int, &Example::m_integer> },
|
||||
|
||||
{ "getUInteger", luaWrapper::utils::get<Example, unsigned int, &Example::m_uinteger> },
|
||||
{ "setUInteger", luaWrapper::utils::set<Example, unsigned int, &Example::m_uinteger> },
|
||||
{ "m_uinteger", luaWrapper::utils::getset<Example, unsigned int, &Example::m_uinteger> },
|
||||
{ "m_uinteger", luaWrapper::utils::getSet<Example, unsigned int, &Example::m_uinteger> },
|
||||
|
||||
{ "getCString", luaWrapper::utils::get<Example, const char*, &Example::m_cstring> },
|
||||
{ "setCString", luaWrapper::utils::set<Example, const char*, &Example::m_cstring> },
|
||||
{ "m_string", luaWrapper::utils::getset<Example, const char*, &Example::m_cstring> },
|
||||
{ "m_string", luaWrapper::utils::getSet<Example, const char*, &Example::m_cstring> },
|
||||
|
||||
{ "getCPPString", luaWrapper::utils::get<Example, etk::String, &Example::m_cppstring> },
|
||||
{ "setCPPString", luaWrapper::utils::set<Example, etk::String, &Example::m_cppstring> },
|
||||
{ "m_cppstring", luaWrapper::utils::getset<Example, etk::String, &Example::m_cppstring> },
|
||||
{ "m_cppstring", luaWrapper::utils::getSet<Example, etk::String, &Example::m_cppstring> },
|
||||
|
||||
{ "getVec", luaWrapper::utils::get<Example, Vector2D, &Example::m_vec> },
|
||||
{ "setVec", luaWrapper::utils::set<Example, Vector2D, &Example::m_vec> },
|
||||
{ "m_vec", luaWrapper::utils::getset<Example, Vector2D, &Example::m_vec> },
|
||||
{ "m_vec", luaWrapper::utils::getSet<Example, Vector2D, &Example::m_vec> },
|
||||
|
||||
{ "getNumber", luaWrapper::utils::get<Example, double, &Example::m_number> },
|
||||
{ "setNumber", luaWrapper::utils::set<Example, double, &Example::m_number> },
|
||||
{ "m_number", luaWrapper::utils::getset<Example, double, &Example::m_number> },
|
||||
{ "m_number", luaWrapper::utils::getSet<Example, double, &Example::m_number> },
|
||||
|
||||
{ "getFloatNumber", luaWrapper::utils::get<Example, float, &Example::m_floatnumber> },
|
||||
{ "setFloatNumber", luaWrapper::utils::set<Example, float, &Example::m_floatnumber> },
|
||||
{ "m_floatnumber", luaWrapper::utils::getset<Example, float, &Example::m_floatnumber> },
|
||||
{ "m_floatnumber", luaWrapper::utils::getSet<Example, float, &Example::m_floatnumber> },
|
||||
|
||||
{ "getPtr", luaWrapper::utils::get<Example, Example, &Example::m_ptr> },
|
||||
{ "setPtr", luaWrapper::utils::set<Example, Example, &Example::m_ptr> },
|
||||
{ "Ptr", luaWrapper::utils::getset<Example, Example, &Example::m_ptr> },
|
||||
{ "Ptr", luaWrapper::utils::getSet<Example, Example, &Example::m_ptr> },
|
||||
|
||||
// The getters and setters above work on member variables directly, but
|
||||
// sometimes all you have are getter and setter functions instead of
|
||||
// variables. You can still automate the creation of Getter and Setter Lua
|
||||
// variables. You can still automate the creation of getter and setter Lua
|
||||
// function wrappers.
|
||||
|
||||
// Normally it would be silly to have getter and setter functions for both
|
||||
@ -85,55 +85,55 @@ static luaL_Reg Example_metatable[] = {
|
||||
// Class | data type | getter
|
||||
// Class | data type | setter
|
||||
// Class | data type | getter | setter
|
||||
{ "getBooleanFunc", luaWrapper::utils::get<Example, bool, &Example::GetBoolean> },
|
||||
{ "setBooleanFunc", luaWrapper::utils::set<Example, bool, &Example::SetBoolean> },
|
||||
{ "BooleanFunc", luaWrapper::utils::getset<Example, bool, &Example::GetBoolean, &Example::SetBoolean> },
|
||||
{ "getBooleanFunc", luaWrapper::utils::get<Example, bool, &Example::getBoolean> },
|
||||
{ "setBooleanFunc", luaWrapper::utils::set<Example, bool, &Example::setBoolean> },
|
||||
{ "BooleanFunc", luaWrapper::utils::getSet<Example, bool, &Example::getBoolean, &Example::setBoolean> },
|
||||
|
||||
{ "getIntegerFunc", luaWrapper::utils::get<Example, int, &Example::GetInteger> },
|
||||
{ "setIntegerFunc", luaWrapper::utils::set<Example, int, &Example::SetInteger> },
|
||||
{ "IntegerFunc", luaWrapper::utils::getset<Example, int, &Example::GetInteger, &Example::SetInteger> },
|
||||
{ "getIntegerFunc", luaWrapper::utils::get<Example, int, &Example::getInteger> },
|
||||
{ "setIntegerFunc", luaWrapper::utils::set<Example, int, &Example::setInteger> },
|
||||
{ "IntegerFunc", luaWrapper::utils::getSet<Example, int, &Example::getInteger, &Example::setInteger> },
|
||||
|
||||
{ "getUIntegerFunc", luaWrapper::utils::get<Example, unsigned int, &Example::GetUInteger> },
|
||||
{ "setUIntegerFunc", luaWrapper::utils::set<Example, unsigned int, &Example::SetUInteger> },
|
||||
{ "UIntegerFunc", luaWrapper::utils::getset<Example, unsigned int, &Example::GetUInteger, &Example::SetUInteger> },
|
||||
{ "getUIntegerFunc", luaWrapper::utils::get<Example, unsigned int, &Example::getUInteger> },
|
||||
{ "setUIntegerFunc", luaWrapper::utils::set<Example, unsigned int, &Example::setUInteger> },
|
||||
{ "UIntegerFunc", luaWrapper::utils::getSet<Example, unsigned int, &Example::getUInteger, &Example::setUInteger> },
|
||||
|
||||
{ "getCStringFunc", luaWrapper::utils::get<Example, const char*, &Example::GetCString> },
|
||||
{ "setCStringFunc", luaWrapper::utils::set<Example, const char*, &Example::SetCString> },
|
||||
{ "CStringFunc", luaWrapper::utils::getset<Example, const char*, &Example::GetCString, &Example::SetCString> },
|
||||
{ "getCStringFunc", luaWrapper::utils::get<Example, const char*, &Example::getCString> },
|
||||
{ "setCStringFunc", luaWrapper::utils::set<Example, const char*, &Example::setCString> },
|
||||
{ "CStringFunc", luaWrapper::utils::getSet<Example, const char*, &Example::getCString, &Example::setCString> },
|
||||
|
||||
{ "getNumberFunc", luaWrapper::utils::get<Example, double, &Example::GetNumber> },
|
||||
{ "setNumberFunc", luaWrapper::utils::set<Example, double, &Example::SetNumber> },
|
||||
{ "NumberFunc", luaWrapper::utils::getset<Example, double, &Example::GetNumber, &Example::SetNumber> },
|
||||
{ "getNumberFunc", luaWrapper::utils::get<Example, double, &Example::getNumber> },
|
||||
{ "setNumberFunc", luaWrapper::utils::set<Example, double, &Example::setNumber> },
|
||||
{ "NumberFunc", luaWrapper::utils::getSet<Example, double, &Example::getNumber, &Example::setNumber> },
|
||||
|
||||
{ "getFloatNumberFunc", luaWrapper::utils::get<Example, float, &Example::GetFloatNumber> },
|
||||
{ "setFloatNumberFunc", luaWrapper::utils::set<Example, float, &Example::SetFloatNumber> },
|
||||
{ "FloatNumberFunc", luaWrapper::utils::getset<Example, float, &Example::GetFloatNumber, &Example::SetFloatNumber> },
|
||||
{ "getFloatNumberFunc", luaWrapper::utils::get<Example, float, &Example::getFloatNumber> },
|
||||
{ "setFloatNumberFunc", luaWrapper::utils::set<Example, float, &Example::setFloatNumber> },
|
||||
{ "FloatNumberFunc", luaWrapper::utils::getSet<Example, float, &Example::getFloatNumber, &Example::setFloatNumber> },
|
||||
|
||||
{ "getPtrFunc", luaWrapper::utils::get<Example, Example, &Example::GetPtr> },
|
||||
{ "setPtrFunc", luaWrapper::utils::set<Example, Example, &Example::SetPtr> },
|
||||
{ "PtrFunc", luaWrapper::utils::getset<Example, Example, &Example::GetPtr, &Example::SetPtr> },
|
||||
{ "getPtrFunc", luaWrapper::utils::get<Example, Example, &Example::getPtr> },
|
||||
{ "setPtrFunc", luaWrapper::utils::set<Example, Example, &Example::setPtr> },
|
||||
{ "PtrFunc", luaWrapper::utils::getSet<Example, Example, &Example::getPtr, &Example::setPtr> },
|
||||
|
||||
// In order to use luaWrapper::utils::get and luaWrapper::utils::set on non-primitive types, you must define luaWrapper::utils::to
|
||||
// and luaWrapper::utils::check for that type.
|
||||
// See LuaCustomTypes.hpp for an example involving etk::String and Vector2D
|
||||
{ "getCPPStringFunc", luaWrapper::utils::get<Example, etk::String, &Example::GetCPPString> },
|
||||
{ "setCPPStringFunc", luaWrapper::utils::set<Example, etk::String, &Example::SetCPPString> },
|
||||
{ "CPPStringFunc", luaWrapper::utils::getset<Example, etk::String, &Example::GetCPPString, &Example::SetCPPString> },
|
||||
{ "getCPPStringFunc", luaWrapper::utils::get<Example, etk::String, &Example::getCPPString> },
|
||||
{ "setCPPStringFunc", luaWrapper::utils::set<Example, etk::String, &Example::setCPPString> },
|
||||
{ "CPPStringFunc", luaWrapper::utils::getSet<Example, etk::String, &Example::getCPPString, &Example::setCPPString> },
|
||||
|
||||
{ "getVecFunc", luaWrapper::utils::get<Example, Vector2D, &Example::GetVec> },
|
||||
{ "setSetFunc", luaWrapper::utils::set<Example, Vector2D, &Example::SetVec> },
|
||||
{ "VecFunc", luaWrapper::utils::getset<Example, Vector2D, &Example::GetVec, &Example::SetVec> },
|
||||
{ "getVecFunc", luaWrapper::utils::get<Example, Vector2D, &Example::getVec> },
|
||||
{ "setsetFunc", luaWrapper::utils::set<Example, Vector2D, &Example::setVec> },
|
||||
{ "VecFunc", luaWrapper::utils::getSet<Example, Vector2D, &Example::getVec, &Example::setVec> },
|
||||
|
||||
{ "DoSomething", luaWrapperUtils_func(&Example::DoSomething) },
|
||||
{ "DoSomething2", luaWrapperUtils_func(&Example::DoSomething2) },
|
||||
{ "doSomething", luaWrapperUtils_func(&Example::doSomething) },
|
||||
{ "doSomething2", luaWrapperUtils_func(&Example::doSomething2) },
|
||||
|
||||
//{ "DoSomethingElse1", luaWrapper::utils::funcsig(int, Example, DoSomethingElse, int, int) },
|
||||
//{ "DoSomethingElse2", luaWrapper::utils::funcsig(int, Example, DoSomethingElse, float) },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_Example(lua_State* _L) {
|
||||
luaWrapper::registerElement<Example>(_L, "Example", NULL, Example_metatable);
|
||||
int luaopen_Example(luaWrapper:Lua& _lua) {
|
||||
_lua.registerElement<Example>("Example", NULL, Example_metatable);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
struct lua_State;
|
||||
int luaopen_Example(lua_State* _L);
|
||||
int luaopen_Example(luaWrapper:Lua& _lua);
|
||||
|
||||
|
@ -28,4 +28,6 @@ for k, v in pairs(vec2) do
|
||||
print(k, v)
|
||||
end
|
||||
|
||||
ex:printMe()
|
||||
ex:printMe()
|
||||
|
||||
ex:doSomething(true, 12432)
|
||||
|
@ -31,12 +31,12 @@ int main(int _argc, const char *_argv[]) {
|
||||
}
|
||||
}
|
||||
if (inputFileName.empty() == true) {
|
||||
TEST_ERROR("missing file...");
|
||||
usage();
|
||||
TEST_WARNING("missing file... ==> select default one");
|
||||
inputFileName = "DATA:example2.lua";
|
||||
}
|
||||
{
|
||||
luaWrapper::Lua lua;
|
||||
luaopen_Example(lua.getState());
|
||||
luaopen_Example(lua);
|
||||
lua.executeFile(inputFileName);
|
||||
}
|
||||
TEST_PRINT("END SAMPLE 2");
|
||||
|
Loading…
x
Reference in New Issue
Block a user