mirror of
https://github.com/holub/mame
synced 2025-10-06 17:08:28 +03:00
Added LuaBridge and exposed few classes as example (nw)
This commit is contained in:
parent
bb4db66af1
commit
6d33394fb6
15
.gitattributes
vendored
15
.gitattributes
vendored
@ -3956,6 +3956,21 @@ src/lib/libjpeg/jutils.c svneol=native#text/plain
|
|||||||
src/lib/libjpeg/jversion.h svneol=native#text/plain
|
src/lib/libjpeg/jversion.h svneol=native#text/plain
|
||||||
src/lib/libjpeg/libjpeg.txt svneol=native#text/plain
|
src/lib/libjpeg/libjpeg.txt svneol=native#text/plain
|
||||||
src/lib/lua/Makefile svneol=native#text/plain
|
src/lib/lua/Makefile svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/LuaBridge.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/CFunctions.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/ClassInfo.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/Constructor.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/FuncTraits.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/Iterator.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/LuaException.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/LuaHelpers.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/LuaRef.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/Namespace.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/Stack.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/TypeList.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/TypeTraits.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/Userdata.h svneol=native#text/plain
|
||||||
|
src/lib/lua/bridge/detail/dump.h svneol=native#text/plain
|
||||||
src/lib/lua/lapi.c svneol=native#text/plain
|
src/lib/lua/lapi.c svneol=native#text/plain
|
||||||
src/lib/lua/lapi.h svneol=native#text/plain
|
src/lib/lua/lapi.h svneol=native#text/plain
|
||||||
src/lib/lua/lauxlib.c svneol=native#text/plain
|
src/lib/lua/lauxlib.c svneol=native#text/plain
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
#include "lua/lib/lualibs.h"
|
#include "lua/lib/lualibs.h"
|
||||||
#include "web/mongoose.h"
|
#include "web/mongoose.h"
|
||||||
|
#include "lua/bridge/LuaBridge.h"
|
||||||
|
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
// LUA ENGINE
|
// LUA ENGINE
|
||||||
@ -341,28 +342,6 @@ int lua_engine::l_emu_start(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------
|
|
||||||
// luaopen_emu - connect emu section lib
|
|
||||||
//-------------------------------------------------
|
|
||||||
|
|
||||||
int lua_engine::luaopen_emu(lua_State *L)
|
|
||||||
{
|
|
||||||
static const struct luaL_Reg emu_funcs [] = {
|
|
||||||
{ "gamename", l_emu_gamename },
|
|
||||||
{ "keypost", l_emu_keypost },
|
|
||||||
{ "hook_output", l_emu_hook_output },
|
|
||||||
{ "time", l_emu_time },
|
|
||||||
{ "wait", l_emu_wait },
|
|
||||||
{ "after", l_emu_after },
|
|
||||||
{ "exit", l_emu_exit },
|
|
||||||
{ "start", l_emu_start },
|
|
||||||
{ NULL, NULL } /* sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
luaL_newlib(L, emu_funcs);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int lua_engine::luaopen_ioport(lua_State *L)
|
int lua_engine::luaopen_ioport(lua_State *L)
|
||||||
{
|
{
|
||||||
static const struct luaL_Reg ioport_funcs [] = {
|
static const struct luaL_Reg ioport_funcs [] = {
|
||||||
@ -466,7 +445,6 @@ lua_engine::lua_engine()
|
|||||||
luaL_openlibs(m_lua_state); /* open libraries */
|
luaL_openlibs(m_lua_state); /* open libraries */
|
||||||
|
|
||||||
luaopen_lsqlite3(m_lua_state);
|
luaopen_lsqlite3(m_lua_state);
|
||||||
luaL_requiref(m_lua_state, "emu", luaopen_emu, 1);
|
|
||||||
|
|
||||||
luaopen_ioport(m_lua_state);
|
luaopen_ioport(m_lua_state);
|
||||||
|
|
||||||
@ -515,6 +493,36 @@ void lua_engine::update_machine()
|
|||||||
|
|
||||||
void lua_engine::initialize()
|
void lua_engine::initialize()
|
||||||
{
|
{
|
||||||
|
luabridge::getGlobalNamespace (m_lua_state)
|
||||||
|
.beginNamespace ("emu")
|
||||||
|
.addCFunction ("gamename", l_emu_gamename )
|
||||||
|
.addCFunction ("keypost", l_emu_keypost )
|
||||||
|
.addCFunction ("hook_output", l_emu_hook_output )
|
||||||
|
.addCFunction ("time", l_emu_time )
|
||||||
|
.addCFunction ("wait", l_emu_wait )
|
||||||
|
.addCFunction ("after", l_emu_after )
|
||||||
|
.addCFunction ("exit", l_emu_exit )
|
||||||
|
.addCFunction ("start", l_emu_start )
|
||||||
|
.beginClass <machine_manager> ("manager")
|
||||||
|
.addFunction ("machine", &machine_manager::machine)
|
||||||
|
.addFunction ("options", &machine_manager::options)
|
||||||
|
.endClass ()
|
||||||
|
.beginClass <running_machine> ("machine")
|
||||||
|
.addFunction ("exit", &running_machine::schedule_exit)
|
||||||
|
.addFunction ("hard_reset", &running_machine::schedule_hard_reset)
|
||||||
|
.addFunction ("soft_reset", &running_machine::schedule_soft_reset)
|
||||||
|
.addFunction ("system", &running_machine::system)
|
||||||
|
.endClass ()
|
||||||
|
.beginClass <game_driver> ("game_driver")
|
||||||
|
.addData ("name", &game_driver::name)
|
||||||
|
.addData ("description", &game_driver::description)
|
||||||
|
.addData ("year", &game_driver::year)
|
||||||
|
.addData ("manufacturer", &game_driver::manufacturer)
|
||||||
|
.endClass ()
|
||||||
|
.endNamespace ();
|
||||||
|
luabridge::push (m_lua_state, machine_manager::instance());
|
||||||
|
lua_setglobal(m_lua_state, "manager");
|
||||||
|
|
||||||
mg_start_thread(::serve_lua, this);
|
mg_start_thread(::serve_lua, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,6 @@ private:
|
|||||||
void resume(void *L, INT32 param);
|
void resume(void *L, INT32 param);
|
||||||
void report_errors(int status);
|
void report_errors(int status);
|
||||||
void start();
|
void start();
|
||||||
static int luaopen_emu(lua_State *L);
|
|
||||||
static int luaopen_ioport(lua_State *L);
|
static int luaopen_ioport(lua_State *L);
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
142
src/lib/lua/bridge/LuaBridge.h
Normal file
142
src/lib/lua/bridge/LuaBridge.h
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
Copyright 2007, Nathan Reed
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#ifndef LUABRIDGE_LUABRIDGE_HEADER
|
||||||
|
#define LUABRIDGE_LUABRIDGE_HEADER
|
||||||
|
|
||||||
|
// All #include dependencies are listed here
|
||||||
|
// instead of in the individual header files.
|
||||||
|
//
|
||||||
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#define LUABRIDGE_MAJOR_VERSION 2
|
||||||
|
#define LUABRIDGE_MINOR_VERSION 0
|
||||||
|
#define LUABRIDGE_VERSION 200
|
||||||
|
|
||||||
|
namespace luabridge
|
||||||
|
{
|
||||||
|
|
||||||
|
// Forward declaration
|
||||||
|
//
|
||||||
|
template <class T>
|
||||||
|
struct Stack;
|
||||||
|
|
||||||
|
#include "detail/LuaHelpers.h"
|
||||||
|
|
||||||
|
#include "detail/TypeTraits.h"
|
||||||
|
#include "detail/TypeList.h"
|
||||||
|
#include "detail/FuncTraits.h"
|
||||||
|
#include "detail/Constructor.h"
|
||||||
|
#include "detail/Stack.h"
|
||||||
|
#include "detail/ClassInfo.h"
|
||||||
|
|
||||||
|
class LuaRef;
|
||||||
|
|
||||||
|
#include "detail/LuaException.h"
|
||||||
|
#include "detail/LuaRef.h"
|
||||||
|
#include "detail/Iterator.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
security options.
|
||||||
|
*/
|
||||||
|
class Security
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool hideMetatables ()
|
||||||
|
{
|
||||||
|
return getSettings().hideMetatables;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setHideMetatables (bool shouldHide)
|
||||||
|
{
|
||||||
|
getSettings().hideMetatables = shouldHide;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Settings
|
||||||
|
{
|
||||||
|
Settings () : hideMetatables (true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hideMetatables;
|
||||||
|
};
|
||||||
|
|
||||||
|
static Settings& getSettings ()
|
||||||
|
{
|
||||||
|
static Settings settings;
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "detail/Userdata.h"
|
||||||
|
#include "detail/CFunctions.h"
|
||||||
|
#include "detail/Namespace.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Push an object onto the Lua stack.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
inline void push (lua_State* L, T t)
|
||||||
|
{
|
||||||
|
Stack <T>::push (L, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Set a global value in the lua_State.
|
||||||
|
|
||||||
|
@note This works on any type specialized by `Stack`, including `LuaRef` and
|
||||||
|
its table proxies.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
inline void setGlobal (lua_State* L, T t, char const* name)
|
||||||
|
{
|
||||||
|
push (L, t);
|
||||||
|
lua_setglobal (L, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Change whether or not metatables are hidden (on by default).
|
||||||
|
*/
|
||||||
|
inline void setHideMetatables (bool shouldHide)
|
||||||
|
{
|
||||||
|
Security::setHideMetatables (shouldHide);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
442
src/lib/lua/bridge/detail/CFunctions.h
Normal file
442
src/lib/lua/bridge/detail/CFunctions.h
Normal file
@ -0,0 +1,442 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
// We use a structure so we can define everything in the header.
|
||||||
|
//
|
||||||
|
struct CFunc
|
||||||
|
{
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
__index metamethod for a namespace or class static members.
|
||||||
|
|
||||||
|
This handles:
|
||||||
|
Retrieving functions and class static methods, stored in the metatable.
|
||||||
|
Reading global and class static data, stored in the __propget table.
|
||||||
|
Reading global and class properties, stored in the __propget table.
|
||||||
|
*/
|
||||||
|
static int indexMetaMethod (lua_State* L)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
lua_getmetatable (L, 1); // push metatable of arg1
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
lua_pushvalue (L, 2); // push key arg2
|
||||||
|
lua_rawget (L, -2); // lookup key in metatable
|
||||||
|
if (lua_isnil (L, -1)) // not found
|
||||||
|
{
|
||||||
|
lua_pop (L, 1); // discard nil
|
||||||
|
rawgetfield (L, -1, "__propget"); // lookup __propget in metatable
|
||||||
|
lua_pushvalue (L, 2); // push key arg2
|
||||||
|
lua_rawget (L, -2); // lookup key in __propget
|
||||||
|
lua_remove (L, -2); // discard __propget
|
||||||
|
if (lua_iscfunction (L, -1))
|
||||||
|
{
|
||||||
|
lua_remove (L, -2); // discard metatable
|
||||||
|
lua_pushvalue (L, 1); // push arg1
|
||||||
|
lua_call (L, 1, 1); // call cfunction
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert (lua_isnil (L, -1));
|
||||||
|
lua_pop (L, 1); // discard nil and fall through
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert (lua_istable (L, -1) || lua_iscfunction (L, -1));
|
||||||
|
lua_remove (L, -2);
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rawgetfield (L, -1, "__parent");
|
||||||
|
if (lua_istable (L, -1))
|
||||||
|
{
|
||||||
|
// Remove metatable and repeat the search in __parent.
|
||||||
|
lua_remove (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Discard metatable and return nil.
|
||||||
|
assert (lua_isnil (L, -1));
|
||||||
|
lua_remove (L, -2);
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
__newindex metamethod for a namespace or class static members.
|
||||||
|
|
||||||
|
The __propset table stores proxy functions for assignment to:
|
||||||
|
Global and class static data.
|
||||||
|
Global and class properties.
|
||||||
|
*/
|
||||||
|
static int newindexMetaMethod (lua_State* L)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
lua_getmetatable (L, 1); // push metatable of arg1
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
rawgetfield (L, -1, "__propset"); // lookup __propset in metatable
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_pushvalue (L, 2); // push key arg2
|
||||||
|
lua_rawget (L, -2); // lookup key in __propset
|
||||||
|
lua_remove (L, -2); // discard __propset
|
||||||
|
if (lua_iscfunction (L, -1)) // ensure value is a cfunction
|
||||||
|
{
|
||||||
|
lua_remove (L, -2); // discard metatable
|
||||||
|
lua_pushvalue (L, 3); // push new value arg3
|
||||||
|
lua_call (L, 1, 0); // call cfunction
|
||||||
|
result = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert (lua_isnil (L, -1));
|
||||||
|
lua_pop (L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
rawgetfield (L, -1, "__parent");
|
||||||
|
if (lua_istable (L, -1))
|
||||||
|
{
|
||||||
|
// Remove metatable and repeat the search in __parent.
|
||||||
|
lua_remove (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert (lua_isnil (L, -1));
|
||||||
|
lua_pop (L, 2);
|
||||||
|
result = luaL_error (L,"no writable variable '%s'", lua_tostring (L, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to report an error writing to a read-only value.
|
||||||
|
|
||||||
|
The name of the variable is in the first upvalue.
|
||||||
|
*/
|
||||||
|
static int readOnlyError (lua_State* L)
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
|
||||||
|
s = s + "'" + lua_tostring (L, lua_upvalueindex (1)) + "' is read-only";
|
||||||
|
|
||||||
|
return luaL_error (L, s.c_str ());
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to get a variable.
|
||||||
|
|
||||||
|
This is used for global variables or class static data members.
|
||||||
|
|
||||||
|
The pointer to the data is in the first upvalue.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static int getVariable (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (lua_islightuserdata (L, lua_upvalueindex (1)));
|
||||||
|
T const* ptr = static_cast <T const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (ptr != 0);
|
||||||
|
Stack <T>::push (L, *ptr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to set a variable.
|
||||||
|
|
||||||
|
This is used for global variables or class static data members.
|
||||||
|
|
||||||
|
The pointer to the data is in the first upvalue.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static int setVariable (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (lua_islightuserdata (L, lua_upvalueindex (1)));
|
||||||
|
T* ptr = static_cast <T*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (ptr != 0);
|
||||||
|
*ptr = Stack <T>::get (L, 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to call a function with a return value.
|
||||||
|
|
||||||
|
This is used for global functions, global properties, class static methods,
|
||||||
|
and class static properties.
|
||||||
|
|
||||||
|
The function pointer is in the first upvalue.
|
||||||
|
*/
|
||||||
|
template <class FnPtr,
|
||||||
|
class ReturnType = typename FuncTraits <FnPtr>::ReturnType>
|
||||||
|
struct Call
|
||||||
|
{
|
||||||
|
typedef typename FuncTraits <FnPtr>::Params Params;
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
FnPtr const& fnptr = *static_cast <FnPtr const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
ArgList <Params> args (L);
|
||||||
|
Stack <typename FuncTraits <FnPtr>::ReturnType>::push (L, FuncTraits <FnPtr>::call (fnptr, args));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to call a function with no return value.
|
||||||
|
|
||||||
|
This is used for global functions, global properties, class static methods,
|
||||||
|
and class static properties.
|
||||||
|
|
||||||
|
The function pointer is in the first upvalue.
|
||||||
|
*/
|
||||||
|
template <class FnPtr>
|
||||||
|
struct Call <FnPtr, void>
|
||||||
|
{
|
||||||
|
typedef typename FuncTraits <FnPtr>::Params Params;
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
FnPtr const& fnptr = *static_cast <FnPtr const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
ArgList <Params> args (L);
|
||||||
|
FuncTraits <FnPtr>::call (fnptr, args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to call a class member function with a return value.
|
||||||
|
|
||||||
|
The member function pointer is in the first upvalue.
|
||||||
|
The class userdata object is at the top of the Lua stack.
|
||||||
|
*/
|
||||||
|
template <class MemFnPtr,
|
||||||
|
class ReturnType = typename FuncTraits <MemFnPtr>::ReturnType>
|
||||||
|
struct CallMember
|
||||||
|
{
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::ClassType T;
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::Params Params;
|
||||||
|
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
T* const t = Userdata::get <T> (L, 1, false);
|
||||||
|
MemFnPtr const& fnptr = *static_cast <MemFnPtr const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
ArgList <Params, 2> args (L);
|
||||||
|
Stack <ReturnType>::push (L, FuncTraits <MemFnPtr>::call (t, fnptr, args));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class MemFnPtr,
|
||||||
|
class ReturnType = typename FuncTraits <MemFnPtr>::ReturnType>
|
||||||
|
struct CallConstMember
|
||||||
|
{
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::ClassType T;
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::Params Params;
|
||||||
|
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
T const* const t = Userdata::get <T> (L, 1, true);
|
||||||
|
MemFnPtr const& fnptr = *static_cast <MemFnPtr const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
ArgList <Params, 2> args(L);
|
||||||
|
Stack <ReturnType>::push (L, FuncTraits <MemFnPtr>::call (t, fnptr, args));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to call a class member function with no return value.
|
||||||
|
|
||||||
|
The member function pointer is in the first upvalue.
|
||||||
|
The class userdata object is at the top of the Lua stack.
|
||||||
|
*/
|
||||||
|
template <class MemFnPtr>
|
||||||
|
struct CallMember <MemFnPtr, void>
|
||||||
|
{
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::ClassType T;
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::Params Params;
|
||||||
|
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
T* const t = Userdata::get <T> (L, 1, false);
|
||||||
|
MemFnPtr const& fnptr = *static_cast <MemFnPtr const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
ArgList <Params, 2> args (L);
|
||||||
|
FuncTraits <MemFnPtr>::call (t, fnptr, args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class MemFnPtr>
|
||||||
|
struct CallConstMember <MemFnPtr, void>
|
||||||
|
{
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::ClassType T;
|
||||||
|
typedef typename FuncTraits <MemFnPtr>::Params Params;
|
||||||
|
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
T const* const t = Userdata::get <T> (L, 1, true);
|
||||||
|
MemFnPtr const& fnptr = *static_cast <MemFnPtr const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
ArgList <Params, 2> args (L);
|
||||||
|
FuncTraits <MemFnPtr>::call (t, fnptr, args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to call a class member lua_CFunction.
|
||||||
|
|
||||||
|
The member function pointer is in the first upvalue.
|
||||||
|
The class userdata object is at the top of the Lua stack.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
struct CallMemberCFunction
|
||||||
|
{
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
typedef int (T::*MFP)(lua_State* L);
|
||||||
|
T* const t = Userdata::get <T> (L, 1, false);
|
||||||
|
MFP const& fnptr = *static_cast <MFP const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
return (t->*fnptr) (L);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct CallConstMemberCFunction
|
||||||
|
{
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
assert (isfulluserdata (L, lua_upvalueindex (1)));
|
||||||
|
typedef int (T::*MFP)(lua_State* L);
|
||||||
|
T const* const t = Userdata::get <T> (L, 1, true);
|
||||||
|
MFP const& fnptr = *static_cast <MFP const*> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
assert (fnptr != 0);
|
||||||
|
return (t->*fnptr) (L);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// SFINAE Helpers
|
||||||
|
|
||||||
|
template <class MemFnPtr, bool isConst>
|
||||||
|
struct CallMemberFunctionHelper
|
||||||
|
{
|
||||||
|
static void add (lua_State* L, char const* name, MemFnPtr mf)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (MemFnPtr))) MemFnPtr (mf);
|
||||||
|
lua_pushcclosure (L, &CallConstMember <MemFnPtr>::f, 1);
|
||||||
|
lua_pushvalue (L, -1);
|
||||||
|
rawsetfield (L, -5, name); // const table
|
||||||
|
rawsetfield (L, -3, name); // class table
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class MemFnPtr>
|
||||||
|
struct CallMemberFunctionHelper <MemFnPtr, false>
|
||||||
|
{
|
||||||
|
static void add (lua_State* L, char const* name, MemFnPtr mf)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (MemFnPtr))) MemFnPtr (mf);
|
||||||
|
lua_pushcclosure (L, &CallMember <MemFnPtr>::f, 1);
|
||||||
|
rawsetfield (L, -3, name); // class table
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
__gc metamethod for a class.
|
||||||
|
*/
|
||||||
|
template <class C>
|
||||||
|
static int gcMetaMethod (lua_State* L)
|
||||||
|
{
|
||||||
|
Userdata* const ud = Userdata::getExact <C> (L, 1);
|
||||||
|
ud->~Userdata ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to get a class data member.
|
||||||
|
|
||||||
|
The pointer-to-member is in the first upvalue.
|
||||||
|
The class userdata object is at the top of the Lua stack.
|
||||||
|
*/
|
||||||
|
template <class C, typename T>
|
||||||
|
static int getProperty (lua_State* L)
|
||||||
|
{
|
||||||
|
C const* const c = Userdata::get <C> (L, 1, true);
|
||||||
|
T C::** mp = static_cast <T C::**> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
Stack <T>::push (L, c->**mp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
lua_CFunction to set a class data member.
|
||||||
|
|
||||||
|
The pointer-to-member is in the first upvalue.
|
||||||
|
The class userdata object is at the top of the Lua stack.
|
||||||
|
*/
|
||||||
|
template <class C, typename T>
|
||||||
|
static int setProperty (lua_State* L)
|
||||||
|
{
|
||||||
|
C* const c = Userdata::get <C> (L, 1, false);
|
||||||
|
T C::** mp = static_cast <T C::**> (lua_touserdata (L, lua_upvalueindex (1)));
|
||||||
|
c->**mp = Stack <T>::get (L, 2);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
73
src/lib/lua/bridge/detail/ClassInfo.h
Normal file
73
src/lib/lua/bridge/detail/ClassInfo.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
/** Unique Lua registry keys for a class.
|
||||||
|
|
||||||
|
Each registered class inserts three keys into the registry, whose
|
||||||
|
values are the corresponding static, class, and const metatables. This
|
||||||
|
allows a quick and reliable lookup for a metatable from a template type.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
class ClassInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Get the key for the static table.
|
||||||
|
|
||||||
|
The static table holds the static data members, static properties, and
|
||||||
|
static member functions for a class.
|
||||||
|
*/
|
||||||
|
static void const* getStaticKey ()
|
||||||
|
{
|
||||||
|
static char value;
|
||||||
|
return &value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the key for the class table.
|
||||||
|
|
||||||
|
The class table holds the data members, properties, and member functions
|
||||||
|
of a class. Read-only data and properties, and const member functions are
|
||||||
|
also placed here (to save a lookup in the const table).
|
||||||
|
*/
|
||||||
|
static void const* getClassKey ()
|
||||||
|
{
|
||||||
|
static char value;
|
||||||
|
return &value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the key for the const table.
|
||||||
|
|
||||||
|
The const table holds read-only data members and properties, and const
|
||||||
|
member functions of a class.
|
||||||
|
*/
|
||||||
|
static void const* getConstKey ()
|
||||||
|
{
|
||||||
|
static char value;
|
||||||
|
return &value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
204
src/lib/lua/bridge/detail/Constructor.h
Normal file
204
src/lib/lua/bridge/detail/Constructor.h
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
Copyright 2007, Nathan Reed
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#ifndef LUABRIDGE_CONSTRUCTOR_HEADER
|
||||||
|
#define LUABRIDGE_CONSTRUCTOR_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructor generators. These templates allow you to call operator new and
|
||||||
|
* pass the contents of a type/value list to the Constructor. Like the
|
||||||
|
* function pointer containers, these are only defined up to 8 parameters.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Constructor generators.
|
||||||
|
|
||||||
|
These templates call operator new with the contents of a type/value
|
||||||
|
list passed to the Constructor with up to 8 parameters. Two versions
|
||||||
|
of call() are provided. One performs a regular new, the other performs
|
||||||
|
a placement new.
|
||||||
|
*/
|
||||||
|
template <class T, typename List>
|
||||||
|
struct Constructor {};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct Constructor <T, None>
|
||||||
|
{
|
||||||
|
static T* call (TypeListValues <None> const&)
|
||||||
|
{
|
||||||
|
return new T;
|
||||||
|
}
|
||||||
|
static T* call (void* mem, TypeListValues <None> const&)
|
||||||
|
{
|
||||||
|
return new (mem) T;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1>
|
||||||
|
struct Constructor <T, TypeList <P1> >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1> > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1> > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1, class P2>
|
||||||
|
struct Constructor <T, TypeList <P1, TypeList <P2> > >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1, TypeList <P2> > > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2> > > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1, class P2, class P3>
|
||||||
|
struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3> > > >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3> > > > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3> > > > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1, class P2, class P3, class P4>
|
||||||
|
struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
|
||||||
|
TypeList <P4> > > > >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4> > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4> > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1, class P2, class P3, class P4,
|
||||||
|
class P5>
|
||||||
|
struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
|
||||||
|
TypeList <P4, TypeList <P5> > > > > >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5> > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5> > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1, class P2, class P3, class P4,
|
||||||
|
class P5, class P6>
|
||||||
|
struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
|
||||||
|
TypeList <P4, TypeList <P5, TypeList <P6> > > > > > >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1, class P2, class P3, class P4,
|
||||||
|
class P5, class P6, class P7>
|
||||||
|
struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
|
||||||
|
TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
|
||||||
|
TypeList <P7> > > > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
|
||||||
|
TypeList <P7> > > > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class P1, class P2, class P3, class P4,
|
||||||
|
class P5, class P6, class P7, class P8>
|
||||||
|
struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
|
||||||
|
TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7,
|
||||||
|
TypeList <P8> > > > > > > > >
|
||||||
|
{
|
||||||
|
static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
|
||||||
|
TypeList <P7, TypeList <P8> > > > > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
|
||||||
|
TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
|
||||||
|
TypeList <P7, TypeList <P8> > > > > > > > > &tvl)
|
||||||
|
{
|
||||||
|
return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
852
src/lib/lua/bridge/detail/FuncTraits.h
Normal file
852
src/lib/lua/bridge/detail/FuncTraits.h
Normal file
@ -0,0 +1,852 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
Since the throw specification is part of a function signature, the FuncTraits
|
||||||
|
family of templates needs to be specialized for both types. The
|
||||||
|
LUABRIDGE_THROWSPEC macro controls whether we use the 'throw ()' form, or
|
||||||
|
'noexcept' (if C++11 is available) to distinguish the functions.
|
||||||
|
*/
|
||||||
|
#if defined (__APPLE_CPP__) || defined(__APPLE_CC__) || defined(__clang__) || defined(__GNUC__) || \
|
||||||
|
(defined (_MSC_VER) && (_MSC_VER >= 1700))
|
||||||
|
// Do not define LUABRIDGE_THROWSPEC since the Xcode and gcc compilers do not
|
||||||
|
// distinguish the throw specification in the function signature.
|
||||||
|
#else
|
||||||
|
// Visual Studio 10 and earlier pay too much mind to useless throw() spec.
|
||||||
|
//
|
||||||
|
# define LUABRIDGE_THROWSPEC throw()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
/**
|
||||||
|
Traits for function pointers.
|
||||||
|
|
||||||
|
There are three types of functions: global, non-const member, and const
|
||||||
|
member. These templates determine the type of function, which class type it
|
||||||
|
belongs to if it is a class member, the const-ness if it is a member
|
||||||
|
function, and the type information for the return value and argument list.
|
||||||
|
|
||||||
|
Expansions are provided for functions with up to 8 parameters. This can be
|
||||||
|
manually extended, or expanded to an arbitrary amount using C++11 features.
|
||||||
|
*/
|
||||||
|
template <class MemFn, class D = MemFn>
|
||||||
|
struct FuncTraits
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Ordinary function pointers. */
|
||||||
|
|
||||||
|
template <class R, class D>
|
||||||
|
struct FuncTraits <R (*) (), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef None Params;
|
||||||
|
static R call (D fp, TypeListValues <Params>)
|
||||||
|
{
|
||||||
|
return fp ();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class D>
|
||||||
|
struct FuncTraits <R (*) (P1), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1> Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2> > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3> > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4> > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5> > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class P6, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5, P6), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5, P6, P7), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5, P6, P7, P8), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7, TypeList <P8> > > > > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Non-const member function pointers. */
|
||||||
|
|
||||||
|
template <class T, class R, class D>
|
||||||
|
struct FuncTraits <R (T::*) (), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef None Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params>)
|
||||||
|
{
|
||||||
|
return (obj->*fp)();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1> Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2> > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3> > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4> > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5> > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7, P8), D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7, TypeList <P8> > > > > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Const member function pointers. */
|
||||||
|
|
||||||
|
template <class T, class R, class D>
|
||||||
|
struct FuncTraits <R (T::*) () const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef None Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params>)
|
||||||
|
{
|
||||||
|
return (obj->*fp)();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1> Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2> > Params;
|
||||||
|
static R call (T const* obj, R (T::*fp) (P1, P2) const,
|
||||||
|
TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3> > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4> > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5> > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7, P8) const, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7, TypeList <P8> > > > > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined (LUABRIDGE_THROWSPEC)
|
||||||
|
|
||||||
|
/* Ordinary function pointers. */
|
||||||
|
|
||||||
|
template <class R, class D>
|
||||||
|
struct FuncTraits <R (*) () LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef None Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> const&)
|
||||||
|
{
|
||||||
|
return fp ();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class D>
|
||||||
|
struct FuncTraits <R (*) (P1) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1> Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2> > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3> > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4> > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5> > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class P6, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5, P6) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5, P6, P7) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class D>
|
||||||
|
struct FuncTraits <R (*) (P1, P2, P3, P4, P5, P6, P7, P8) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7, TypeList <P8> > > > > > > > Params;
|
||||||
|
static R call (D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return fp (tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Non-const member function pointers with THROWSPEC. */
|
||||||
|
|
||||||
|
template <class T, class R, class D>
|
||||||
|
struct FuncTraits <R (T::*) () LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef None Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> const&)
|
||||||
|
{
|
||||||
|
return (obj->*fp)();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1> Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2> > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3> > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4> > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5> > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7, P8) LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = false;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7, TypeList <P8> > > > > > > > Params;
|
||||||
|
static R call (T* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Const member function pointers with THROWSPEC. */
|
||||||
|
|
||||||
|
template <class T, class R, class D>
|
||||||
|
struct FuncTraits <R (T::*) () const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef None Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params>)
|
||||||
|
{
|
||||||
|
return (obj->*fp)();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1> Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2> > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3> > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4> > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5> > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
|
||||||
|
tvl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class D>
|
||||||
|
struct FuncTraits <R (T::*) (P1, P2, P3, P4, P5, P6, P7, P8) const LUABRIDGE_THROWSPEC, D>
|
||||||
|
{
|
||||||
|
static bool const isMemberFunction = true;
|
||||||
|
static bool const isConstMemberFunction = true;
|
||||||
|
typedef D DeclType;
|
||||||
|
typedef T ClassType;
|
||||||
|
typedef R ReturnType;
|
||||||
|
typedef TypeList <P1, TypeList <P2, TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7, TypeList <P8> > > > > > > > Params;
|
||||||
|
static R call (T const* obj, D fp, TypeListValues <Params> tvl)
|
||||||
|
{
|
||||||
|
return (obj->*fp)(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
114
src/lib/lua/bridge/detail/Iterator.h
Normal file
114
src/lib/lua/bridge/detail/Iterator.h
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
/** Allows table iteration.
|
||||||
|
*/
|
||||||
|
class Iterator
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
lua_State* m_L;
|
||||||
|
LuaRef m_table;
|
||||||
|
LuaRef m_key;
|
||||||
|
LuaRef m_value;
|
||||||
|
|
||||||
|
void next ()
|
||||||
|
{
|
||||||
|
m_table.push(m_L);
|
||||||
|
m_key.push (m_L);
|
||||||
|
if (lua_next (m_L, -2))
|
||||||
|
{
|
||||||
|
m_value.pop (m_L);
|
||||||
|
m_key.pop (m_L);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_key = Nil();
|
||||||
|
m_value = Nil();
|
||||||
|
}
|
||||||
|
lua_pop(m_L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Iterator (LuaRef table)
|
||||||
|
: m_L (table.state ())
|
||||||
|
, m_table (table)
|
||||||
|
, m_key (table.state ()) // m_key is nil
|
||||||
|
, m_value (table.state ()) // m_value is nil
|
||||||
|
{
|
||||||
|
next (); // get the first (key, value) pair from table
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_State* state () const
|
||||||
|
{
|
||||||
|
return m_L;
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaRef operator* () const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaRef operator-> () const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator& operator++ ()
|
||||||
|
{
|
||||||
|
if (isNil())
|
||||||
|
{
|
||||||
|
// if the iterator reaches the end, do nothing
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
next();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool isNil () const
|
||||||
|
{
|
||||||
|
return m_key.isNil ();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline LuaRef key () const
|
||||||
|
{
|
||||||
|
return m_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline LuaRef value () const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Don't use postfix increment, it is less efficient
|
||||||
|
Iterator operator++ (int);
|
||||||
|
};
|
||||||
|
|
113
src/lib/lua/bridge/detail/LuaException.h
Normal file
113
src/lib/lua/bridge/detail/LuaException.h
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
Copyright 2008, Nigel Atkinson <suprapilot+LuaCode@gmail.com>
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
class LuaException : public std::exception
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
lua_State* m_L;
|
||||||
|
std::string m_what;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Construct a LuaException after a lua_pcall().
|
||||||
|
*/
|
||||||
|
LuaException (lua_State* L, int /*code*/)
|
||||||
|
: m_L (L)
|
||||||
|
{
|
||||||
|
whatFromStack ();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
LuaException (lua_State *L,
|
||||||
|
char const*,
|
||||||
|
char const*,
|
||||||
|
long)
|
||||||
|
: m_L (L)
|
||||||
|
{
|
||||||
|
whatFromStack ();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
~LuaException() throw ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
char const* what() const throw ()
|
||||||
|
{
|
||||||
|
return m_what.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
/**
|
||||||
|
Throw an exception.
|
||||||
|
|
||||||
|
This centralizes all the exceptions thrown, so that we can set
|
||||||
|
breakpoints before the stack is unwound, or otherwise customize the
|
||||||
|
behavior.
|
||||||
|
*/
|
||||||
|
template <class Exception>
|
||||||
|
static void Throw (Exception e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Wrapper for lua_pcall that throws.
|
||||||
|
*/
|
||||||
|
static void pcall (lua_State* L, int nargs = 0, int nresults = 0, int msgh = 0)
|
||||||
|
{
|
||||||
|
int code = lua_pcall (L, nargs, nresults, msgh);
|
||||||
|
|
||||||
|
if (code != LUABRIDGE_LUA_OK)
|
||||||
|
Throw (LuaException (L, code));
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void whatFromStack ()
|
||||||
|
{
|
||||||
|
if (lua_gettop (m_L) > 0)
|
||||||
|
{
|
||||||
|
char const* s = lua_tostring (m_L, -1);
|
||||||
|
m_what = s ? s : "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// stack is empty
|
||||||
|
m_what = "missing error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
143
src/lib/lua/bridge/detail/LuaHelpers.h
Normal file
143
src/lib/lua/bridge/detail/LuaHelpers.h
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
Copyright 2007, Nathan Reed
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
// These are for Lua versions prior to 5.2.0.
|
||||||
|
//
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
|
inline int lua_absindex (lua_State* L, int idx)
|
||||||
|
{
|
||||||
|
if (idx > LUA_REGISTRYINDEX && idx < 0)
|
||||||
|
return lua_gettop (L) + idx + 1;
|
||||||
|
else
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void lua_rawgetp (lua_State* L, int idx, void const* p)
|
||||||
|
{
|
||||||
|
idx = lua_absindex (L, idx);
|
||||||
|
lua_pushlightuserdata (L, const_cast <void*> (p));
|
||||||
|
lua_rawget (L,idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void lua_rawsetp (lua_State* L, int idx, void const* p)
|
||||||
|
{
|
||||||
|
idx = lua_absindex (L, idx);
|
||||||
|
lua_pushlightuserdata (L, const_cast <void*> (p));
|
||||||
|
// put key behind value
|
||||||
|
lua_insert (L, -2);
|
||||||
|
lua_rawset (L, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LUA_OPEQ 1
|
||||||
|
#define LUA_OPLT 2
|
||||||
|
#define LUA_OPLE 3
|
||||||
|
|
||||||
|
inline int lua_compare (lua_State* L, int idx1, int idx2, int op)
|
||||||
|
{
|
||||||
|
switch (op)
|
||||||
|
{
|
||||||
|
case LUA_OPEQ:
|
||||||
|
return lua_equal (L, idx1, idx2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LUA_OPLT:
|
||||||
|
return lua_lessthan (L, idx1, idx2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LUA_OPLE:
|
||||||
|
return lua_equal (L, idx1, idx2) || lua_lessthan (L, idx1, idx2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int get_length (lua_State* L, int idx)
|
||||||
|
{
|
||||||
|
return int (lua_objlen (L, idx));
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
inline int get_length (lua_State* L, int idx)
|
||||||
|
{
|
||||||
|
lua_len (L, idx);
|
||||||
|
int len = int (luaL_checknumber (L, -1));
|
||||||
|
lua_pop (L, 1);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LUA_OK
|
||||||
|
# define LUABRIDGE_LUA_OK 0
|
||||||
|
#else
|
||||||
|
# define LUABRIDGE_LUA_OK LUA_OK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Get a table value, bypassing metamethods.
|
||||||
|
*/
|
||||||
|
inline void rawgetfield (lua_State* L, int index, char const* key)
|
||||||
|
{
|
||||||
|
assert (lua_istable (L, index));
|
||||||
|
index = lua_absindex (L, index);
|
||||||
|
lua_pushstring (L, key);
|
||||||
|
lua_rawget (L, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set a table value, bypassing metamethods.
|
||||||
|
*/
|
||||||
|
inline void rawsetfield (lua_State* L, int index, char const* key)
|
||||||
|
{
|
||||||
|
assert (lua_istable (L, index));
|
||||||
|
index = lua_absindex (L, index);
|
||||||
|
lua_pushstring (L, key);
|
||||||
|
lua_insert (L, -2);
|
||||||
|
lua_rawset (L, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if the value is a full userdata (not light).
|
||||||
|
*/
|
||||||
|
inline bool isfulluserdata (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return lua_isuserdata (L, index) && !lua_islightuserdata (L, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test lua_State objects for global equality.
|
||||||
|
|
||||||
|
This can determine if two different lua_State objects really point
|
||||||
|
to the same global state, such as when using coroutines.
|
||||||
|
|
||||||
|
@note This is used for assertions.
|
||||||
|
*/
|
||||||
|
inline bool equalstates (lua_State* L1, lua_State* L2)
|
||||||
|
{
|
||||||
|
return lua_topointer (L1, LUA_REGISTRYINDEX) ==
|
||||||
|
lua_topointer (L2, LUA_REGISTRYINDEX);
|
||||||
|
}
|
1215
src/lib/lua/bridge/detail/LuaRef.h
Normal file
1215
src/lib/lua/bridge/detail/LuaRef.h
Normal file
File diff suppressed because it is too large
Load Diff
1136
src/lib/lua/bridge/detail/Namespace.h
Normal file
1136
src/lib/lua/bridge/detail/Namespace.h
Normal file
File diff suppressed because it is too large
Load Diff
469
src/lib/lua/bridge/detail/Stack.h
Normal file
469
src/lib/lua/bridge/detail/Stack.h
Normal file
@ -0,0 +1,469 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
Copyright 2007, Nathan Reed
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Receive the lua_State* as an argument.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <lua_State*>
|
||||||
|
{
|
||||||
|
static lua_State* get (lua_State* L, int)
|
||||||
|
{
|
||||||
|
return L;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Push a lua_CFunction.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <lua_CFunction>
|
||||||
|
{
|
||||||
|
static void push (lua_State* L, lua_CFunction f)
|
||||||
|
{
|
||||||
|
lua_pushcfunction (L, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static lua_CFunction get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return lua_tocfunction (L, index);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `int`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <int>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, int value)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, static_cast <lua_Integer> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <int> (luaL_checkinteger (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <int const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, int value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <int > (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `unsigned int`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned int>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned int value)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, static_cast <lua_Integer> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned int get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned int> (luaL_checkinteger (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned int const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned int value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned int get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned int > (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `unsigned char`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned char>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned char value)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, static_cast <lua_Integer> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned char get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned char> (luaL_checkinteger (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned char const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned char value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned char get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned char> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `short`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <short>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, short value)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, static_cast <lua_Integer> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline short get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <short> (luaL_checkinteger (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <short const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, short value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline short get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <short> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `unsigned short`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned short>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned short value)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, static_cast <lua_Integer> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned short get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned short> (luaL_checkinteger (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned short const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned short value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned short get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned short> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `long`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <long>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, long value)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, static_cast <lua_Integer> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline long get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <long> (luaL_checkinteger (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <long const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, long value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline long get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <long> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `unsigned long`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned long>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned long value)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, static_cast <lua_Integer> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned long get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned long> (luaL_checkinteger (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <unsigned long const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, unsigned long value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned long get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <unsigned long> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `float`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <float>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, float value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <float> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <float const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, float value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <float> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `double`.
|
||||||
|
*/
|
||||||
|
template <> struct Stack <double>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, double value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline double get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <double> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct Stack <double const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, double value)
|
||||||
|
{
|
||||||
|
lua_pushnumber (L, static_cast <lua_Number> (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline double get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return static_cast <double> (luaL_checknumber (L, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `bool`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <bool> {
|
||||||
|
static inline void push (lua_State* L, bool value)
|
||||||
|
{
|
||||||
|
lua_pushboolean (L, value ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return lua_toboolean (L, index) ? true : false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <bool const&> {
|
||||||
|
static inline void push (lua_State* L, bool value)
|
||||||
|
{
|
||||||
|
lua_pushboolean (L, value ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return lua_toboolean (L, index) ? true : false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `char`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <char>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, char value)
|
||||||
|
{
|
||||||
|
char str [2] = { value, 0 };
|
||||||
|
lua_pushstring (L, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return luaL_checkstring (L, index) [0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Stack <char const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, char value)
|
||||||
|
{
|
||||||
|
char str [2] = { value, 0 };
|
||||||
|
lua_pushstring (L, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return luaL_checkstring (L, index) [0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `float`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <char const*>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, char const* str)
|
||||||
|
{
|
||||||
|
if (str != 0)
|
||||||
|
lua_pushstring (L, str);
|
||||||
|
else
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char const* get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return lua_isnil (L, index) ? 0 : luaL_checkstring (L, index);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `std::string`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <std::string>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, std::string const& str)
|
||||||
|
{
|
||||||
|
lua_pushlstring (L, str.c_str (), str.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline std::string get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
const char *str = luaL_checklstring(L, index, &len);
|
||||||
|
return std::string (str, len);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Stack specialization for `std::string const&`.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct Stack <std::string const&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, std::string const& str)
|
||||||
|
{
|
||||||
|
lua_pushstring (L, str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline std::string get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
const char *str = luaL_checklstring(L, index, &len);
|
||||||
|
return std::string (str, len);
|
||||||
|
}
|
||||||
|
};
|
174
src/lib/lua/bridge/detail/TypeList.h
Normal file
174
src/lib/lua/bridge/detail/TypeList.h
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
Copyright 2007, Nathan Reed
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
This file incorporates work covered by the following copyright and
|
||||||
|
permission notice:
|
||||||
|
|
||||||
|
The Loki Library
|
||||||
|
Copyright (c) 2001 by Andrei Alexandrescu
|
||||||
|
This code accompanies the book:
|
||||||
|
Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
|
||||||
|
Patterns Applied". Copyright (c) 2001. Addison-Wesley.
|
||||||
|
Permission to use, copy, modify, distribute and sell this software for any
|
||||||
|
purpose is hereby granted without fee, provided that the above copyright
|
||||||
|
notice appear in all copies and that both that copyright notice and this
|
||||||
|
permission notice appear in supporting documentation.
|
||||||
|
The author or Addison-Welsey Longman make no representations about the
|
||||||
|
suitability of this software for any purpose. It is provided "as is"
|
||||||
|
without express or implied warranty.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
None type means void parameters or return value.
|
||||||
|
*/
|
||||||
|
typedef void None;
|
||||||
|
|
||||||
|
template <typename Head, typename Tail = None>
|
||||||
|
struct TypeList
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
A TypeList with actual values.
|
||||||
|
*/
|
||||||
|
template <typename List>
|
||||||
|
struct TypeListValues
|
||||||
|
{
|
||||||
|
static std::string const tostring (bool)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
TypeListValues recursive template definition.
|
||||||
|
*/
|
||||||
|
template <typename Head, typename Tail>
|
||||||
|
struct TypeListValues <TypeList <Head, Tail> >
|
||||||
|
{
|
||||||
|
Head hd;
|
||||||
|
TypeListValues <Tail> tl;
|
||||||
|
|
||||||
|
TypeListValues (Head hd_, TypeListValues <Tail> const& tl_)
|
||||||
|
: hd (hd_), tl (tl_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string const tostring (bool comma = false)
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
|
||||||
|
if (comma)
|
||||||
|
s = ", ";
|
||||||
|
|
||||||
|
s = s + typeid (Head).name ();
|
||||||
|
|
||||||
|
return s + TypeListValues <Tail>::tostring (true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Specializations of type/value list for head types that are references and
|
||||||
|
// const-references. We need to handle these specially since we can't count
|
||||||
|
// on the referenced object hanging around for the lifetime of the list.
|
||||||
|
|
||||||
|
template <typename Head, typename Tail>
|
||||||
|
struct TypeListValues <TypeList <Head&, Tail> >
|
||||||
|
{
|
||||||
|
Head hd;
|
||||||
|
TypeListValues <Tail> tl;
|
||||||
|
|
||||||
|
TypeListValues (Head& hd_, TypeListValues <Tail> const& tl_)
|
||||||
|
: hd (hd_), tl (tl_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string const tostring (bool comma = false)
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
|
||||||
|
if (comma)
|
||||||
|
s = ", ";
|
||||||
|
|
||||||
|
s = s + typeid (Head).name () + "&";
|
||||||
|
|
||||||
|
return s + TypeListValues <Tail>::tostring (true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Head, typename Tail>
|
||||||
|
struct TypeListValues <TypeList <Head const&, Tail> >
|
||||||
|
{
|
||||||
|
Head hd;
|
||||||
|
TypeListValues <Tail> tl;
|
||||||
|
|
||||||
|
TypeListValues (Head const& hd_, const TypeListValues <Tail>& tl_)
|
||||||
|
: hd (hd_), tl (tl_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string const tostring (bool comma = false)
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
|
||||||
|
if (comma)
|
||||||
|
s = ", ";
|
||||||
|
|
||||||
|
s = s + typeid (Head).name () + " const&";
|
||||||
|
|
||||||
|
return s + TypeListValues <Tail>::tostring (true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
/**
|
||||||
|
Subclass of a TypeListValues constructable from the Lua stack.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <typename List, int Start = 1>
|
||||||
|
struct ArgList
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <int Start>
|
||||||
|
struct ArgList <None, Start> : public TypeListValues <None>
|
||||||
|
{
|
||||||
|
ArgList (lua_State*)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Head, typename Tail, int Start>
|
||||||
|
struct ArgList <TypeList <Head, Tail>, Start>
|
||||||
|
: public TypeListValues <TypeList <Head, Tail> >
|
||||||
|
{
|
||||||
|
ArgList (lua_State* L)
|
||||||
|
: TypeListValues <TypeList <Head, Tail> > (Stack <Head>::get (L, Start),
|
||||||
|
ArgList <Tail, Start + 1> (L))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
125
src/lib/lua/bridge/detail/TypeTraits.h
Normal file
125
src/lib/lua/bridge/detail/TypeTraits.h
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#ifndef LUABRIDGE_TYPEINFO_HEADER
|
||||||
|
#define LUABRIDGE_TYPEINFO_HEADER
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Container traits.
|
||||||
|
|
||||||
|
Unspecialized ContainerTraits has the isNotContainer typedef for SFINAE.
|
||||||
|
All user defined containers must supply an appropriate specialization for
|
||||||
|
ContinerTraits (without the typedef isNotContainer). The containers that
|
||||||
|
come with LuaBridge also come with the appropriate ContainerTraits
|
||||||
|
specialization. See the corresponding declaration for details.
|
||||||
|
|
||||||
|
A specialization of ContainerTraits for some generic type ContainerType
|
||||||
|
looks like this:
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct ContainerTraits <ContainerType <T> >
|
||||||
|
{
|
||||||
|
typedef typename T Type;
|
||||||
|
|
||||||
|
static T* get (ContainerType <T> const& c)
|
||||||
|
{
|
||||||
|
return c.get (); // Implementation-dependent on ContainerType
|
||||||
|
}
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
struct ContainerTraits
|
||||||
|
{
|
||||||
|
typedef bool isNotContainer;
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Type traits.
|
||||||
|
|
||||||
|
Specializations return information about a type.
|
||||||
|
*/
|
||||||
|
struct TypeTraits
|
||||||
|
{
|
||||||
|
/** Determine if type T is a container.
|
||||||
|
|
||||||
|
To be considered a container, there must be a specialization of
|
||||||
|
ContainerTraits with the required fields.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
class isContainer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
typedef char yes[1]; // sizeof (yes) == 1
|
||||||
|
typedef char no [2]; // sizeof (no) == 2
|
||||||
|
|
||||||
|
template <typename C>
|
||||||
|
static no& test (typename C::isNotContainer*);
|
||||||
|
|
||||||
|
template <typename>
|
||||||
|
static yes& test (...);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const bool value = sizeof (test <ContainerTraits <T> >(0)) == sizeof (yes);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Determine if T is const qualified.
|
||||||
|
*/
|
||||||
|
/** @{ */
|
||||||
|
template <class T>
|
||||||
|
struct isConst
|
||||||
|
{
|
||||||
|
static bool const value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct isConst <T const>
|
||||||
|
{
|
||||||
|
static bool const value = true;
|
||||||
|
};
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
/** Remove the const qualifier from T.
|
||||||
|
*/
|
||||||
|
/** @{ */
|
||||||
|
template <class T>
|
||||||
|
struct removeConst
|
||||||
|
{
|
||||||
|
typedef T Type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct removeConst <T const>
|
||||||
|
{
|
||||||
|
typedef T Type;
|
||||||
|
};
|
||||||
|
/**@}*/
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
817
src/lib/lua/bridge/detail/Userdata.h
Normal file
817
src/lib/lua/bridge/detail/Userdata.h
Normal file
@ -0,0 +1,817 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
https://github.com/vinniefalco/LuaBridge
|
||||||
|
|
||||||
|
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
/**
|
||||||
|
Return the identity pointer for our lightuserdata tokens.
|
||||||
|
|
||||||
|
LuaBridge metatables are tagged with a security "token." The token is a
|
||||||
|
lightuserdata created from the identity pointer, used as a key in the
|
||||||
|
metatable. The value is a boolean = true, although any value could have been
|
||||||
|
used.
|
||||||
|
|
||||||
|
Because of Lua's dynamic typing and our improvised system of imposing C++
|
||||||
|
class structure, there is the possibility that executing scripts may
|
||||||
|
knowingly or unknowingly cause invalid data to get passed to the C functions
|
||||||
|
created by LuaBridge. In particular, our security model addresses the
|
||||||
|
following:
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
1. Scripts cannot create a userdata (ignoring the debug lib).
|
||||||
|
2. Scripts cannot create a lightuserdata (ignoring the debug lib).
|
||||||
|
3. Scripts cannot set the metatable on a userdata.
|
||||||
|
4. Our identity key is a unique pointer in the process.
|
||||||
|
5. Our metatables have a lightuserdata identity key / value pair.
|
||||||
|
6. Our metatables have "__metatable" set to a boolean = false.
|
||||||
|
7. Our lightuserdata is unique.
|
||||||
|
*/
|
||||||
|
inline void* getIdentityKey ()
|
||||||
|
{
|
||||||
|
static char value;
|
||||||
|
return &value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Interface to a class pointer retrievable from a userdata.
|
||||||
|
*/
|
||||||
|
class Userdata
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void* m_p; // subclasses must set this
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Get an untyped pointer to the contained class.
|
||||||
|
*/
|
||||||
|
inline void* const getPointer ()
|
||||||
|
{
|
||||||
|
return m_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Validate and retrieve a Userdata on the stack.
|
||||||
|
|
||||||
|
The Userdata must exactly match the corresponding class table or
|
||||||
|
const table, or else a Lua error is raised. This is used for the
|
||||||
|
__gc metamethod.
|
||||||
|
*/
|
||||||
|
static Userdata* getExactClass (lua_State* L,
|
||||||
|
int narg,
|
||||||
|
void const* classKey)
|
||||||
|
{
|
||||||
|
Userdata* ud = 0;
|
||||||
|
int const index = lua_absindex (L, narg);
|
||||||
|
|
||||||
|
bool mismatch = false;
|
||||||
|
char const* got = 0;
|
||||||
|
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, classKey);
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
|
||||||
|
// Make sure we have a userdata.
|
||||||
|
if (!lua_isuserdata (L, index))
|
||||||
|
mismatch = true;
|
||||||
|
|
||||||
|
// Make sure it's metatable is ours.
|
||||||
|
if (!mismatch)
|
||||||
|
{
|
||||||
|
lua_getmetatable (L, index);
|
||||||
|
lua_rawgetp (L, -1, getIdentityKey ());
|
||||||
|
if (lua_isboolean (L, -1))
|
||||||
|
{
|
||||||
|
lua_pop (L, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pop (L, 2);
|
||||||
|
mismatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mismatch)
|
||||||
|
{
|
||||||
|
if (lua_rawequal (L, -1, -2))
|
||||||
|
{
|
||||||
|
// Matches class table.
|
||||||
|
lua_pop (L, 2);
|
||||||
|
ud = static_cast <Userdata*> (lua_touserdata (L, index));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rawgetfield (L, -2, "__const");
|
||||||
|
if (lua_rawequal (L, -1, -2))
|
||||||
|
{
|
||||||
|
// Matches const table
|
||||||
|
lua_pop (L, 3);
|
||||||
|
ud = static_cast <Userdata*> (lua_touserdata (L, index));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Mismatch, but its one of ours so get a type name.
|
||||||
|
rawgetfield (L, -2, "__type");
|
||||||
|
lua_insert (L, -4);
|
||||||
|
lua_pop (L, 2);
|
||||||
|
got = lua_tostring (L, -2);
|
||||||
|
mismatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mismatch)
|
||||||
|
{
|
||||||
|
rawgetfield (L, -1, "__type");
|
||||||
|
assert (lua_type (L, -1) == LUA_TSTRING);
|
||||||
|
char const* const expected = lua_tostring (L, -1);
|
||||||
|
|
||||||
|
if (got == 0)
|
||||||
|
got = lua_typename (L, lua_type (L, index));
|
||||||
|
|
||||||
|
char const* const msg = lua_pushfstring (
|
||||||
|
L, "%s expected, got %s", expected, got);
|
||||||
|
|
||||||
|
if (narg > 0)
|
||||||
|
luaL_argerror (L, narg, msg);
|
||||||
|
else
|
||||||
|
lua_error (L);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ud;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Validate and retrieve a Userdata on the stack.
|
||||||
|
|
||||||
|
The Userdata must be derived from or the same as the given base class,
|
||||||
|
identified by the key. If canBeConst is false, generates an error if
|
||||||
|
the resulting Userdata represents to a const object. We do the type check
|
||||||
|
first so that the error message is informative.
|
||||||
|
*/
|
||||||
|
static Userdata* getClass (lua_State* L,
|
||||||
|
int index,
|
||||||
|
void const* baseClassKey,
|
||||||
|
bool canBeConst)
|
||||||
|
{
|
||||||
|
assert (index > 0);
|
||||||
|
Userdata* ud = 0;
|
||||||
|
|
||||||
|
bool mismatch = false;
|
||||||
|
char const* got = 0;
|
||||||
|
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, baseClassKey);
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
|
||||||
|
// Make sure we have a userdata.
|
||||||
|
if (lua_isuserdata (L, index))
|
||||||
|
{
|
||||||
|
// Make sure it's metatable is ours.
|
||||||
|
lua_getmetatable (L, index);
|
||||||
|
lua_rawgetp (L, -1, getIdentityKey ());
|
||||||
|
if (lua_isboolean (L, -1))
|
||||||
|
{
|
||||||
|
lua_pop (L, 1);
|
||||||
|
|
||||||
|
// If __const is present, object is NOT const.
|
||||||
|
rawgetfield (L, -1, "__const");
|
||||||
|
assert (lua_istable (L, -1) || lua_isnil (L, -1));
|
||||||
|
bool const isConst = lua_isnil (L, -1);
|
||||||
|
lua_pop (L, 1);
|
||||||
|
|
||||||
|
// Replace the class table with the const table if needed.
|
||||||
|
if (isConst)
|
||||||
|
{
|
||||||
|
rawgetfield (L, -2, "__const");
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_replace (L, -3);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (lua_rawequal (L, -1, -2))
|
||||||
|
{
|
||||||
|
lua_pop (L, 2);
|
||||||
|
|
||||||
|
// Match, now check const-ness.
|
||||||
|
if (isConst && !canBeConst)
|
||||||
|
{
|
||||||
|
luaL_argerror (L, index, "cannot be const");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ud = static_cast <Userdata*> (lua_touserdata (L, index));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Replace current metatable with it's base class.
|
||||||
|
rawgetfield (L, -1, "__parent");
|
||||||
|
/*
|
||||||
|
ud
|
||||||
|
class metatable
|
||||||
|
ud metatable
|
||||||
|
ud __parent (nil)
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (lua_isnil (L, -1))
|
||||||
|
{
|
||||||
|
lua_remove (L, -1);
|
||||||
|
// Mismatch, but its one of ours so get a type name.
|
||||||
|
rawgetfield (L, -1, "__type");
|
||||||
|
lua_insert (L, -3);
|
||||||
|
lua_pop (L, 1);
|
||||||
|
got = lua_tostring (L, -2);
|
||||||
|
mismatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_remove (L, -2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pop (L, 2);
|
||||||
|
mismatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mismatch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mismatch)
|
||||||
|
{
|
||||||
|
assert (lua_type (L, -1) == LUA_TTABLE);
|
||||||
|
rawgetfield (L, -1, "__type");
|
||||||
|
assert (lua_type (L, -1) == LUA_TSTRING);
|
||||||
|
char const* const expected = lua_tostring (L, -1);
|
||||||
|
|
||||||
|
if (got == 0)
|
||||||
|
got = lua_typename (L, lua_type (L, index));
|
||||||
|
|
||||||
|
char const* const msg = lua_pushfstring (
|
||||||
|
L, "%s expected, got %s", expected, got);
|
||||||
|
|
||||||
|
luaL_argerror (L, index, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ud;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~Userdata () { }
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Returns the Userdata* if the class on the Lua stack matches.
|
||||||
|
|
||||||
|
If the class does not match, a Lua error is raised.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static inline Userdata* getExact (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return getExactClass (L, index, ClassInfo <T>::getClassKey ());
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Get a pointer to the class from the Lua stack.
|
||||||
|
|
||||||
|
If the object is not the class or a subclass, or it violates the
|
||||||
|
const-ness, a Lua error is raised.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static inline T* get (lua_State* L, int index, bool canBeConst)
|
||||||
|
{
|
||||||
|
if (lua_isnil (L, index))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return static_cast <T*> (getClass (L, index,
|
||||||
|
ClassInfo <T>::getClassKey (), canBeConst)->getPointer ());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Wraps a class object stored in a Lua userdata.
|
||||||
|
|
||||||
|
The lifetime of the object is managed by Lua. The object is constructed
|
||||||
|
inside the userdata using placement new.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
class UserdataValue : public Userdata
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
UserdataValue <T> (UserdataValue <T> const&);
|
||||||
|
UserdataValue <T> operator= (UserdataValue <T> const&);
|
||||||
|
|
||||||
|
char m_storage [sizeof (T)];
|
||||||
|
|
||||||
|
inline T* getObject ()
|
||||||
|
{
|
||||||
|
// If this fails to compile it means you forgot to provide
|
||||||
|
// a Container specialization for your container!
|
||||||
|
//
|
||||||
|
return reinterpret_cast <T*> (&m_storage [0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
Used for placement construction.
|
||||||
|
*/
|
||||||
|
UserdataValue ()
|
||||||
|
{
|
||||||
|
m_p = getObject ();
|
||||||
|
}
|
||||||
|
|
||||||
|
~UserdataValue ()
|
||||||
|
{
|
||||||
|
getObject ()->~T ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
Push a T via placement new.
|
||||||
|
|
||||||
|
The caller is responsible for calling placement new using the
|
||||||
|
returned uninitialized storage.
|
||||||
|
*/
|
||||||
|
static void* place (lua_State* const L)
|
||||||
|
{
|
||||||
|
UserdataValue <T>* const ud = new (
|
||||||
|
lua_newuserdata (L, sizeof (UserdataValue <T>))) UserdataValue <T> ();
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <T>::getClassKey ());
|
||||||
|
// If this goes off it means you forgot to register the class!
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
return ud->getPointer ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Push T via copy construction from U.
|
||||||
|
*/
|
||||||
|
template <class U>
|
||||||
|
static inline void push (lua_State* const L, U const& u)
|
||||||
|
{
|
||||||
|
new (place (L)) U (u);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Wraps a pointer to a class object inside a Lua userdata.
|
||||||
|
|
||||||
|
The lifetime of the object is managed by C++.
|
||||||
|
*/
|
||||||
|
class UserdataPtr : public Userdata
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
UserdataPtr (UserdataPtr const&);
|
||||||
|
UserdataPtr operator= (UserdataPtr const&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Push non-const pointer to object using metatable key.
|
||||||
|
*/
|
||||||
|
static void push (lua_State* L, void* const p, void const* const key)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (UserdataPtr))) UserdataPtr (p);
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, key);
|
||||||
|
// If this goes off it means you forgot to register the class!
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Push const pointer to object using metatable key.
|
||||||
|
*/
|
||||||
|
static void push (lua_State* L, void const* const p, void const* const key)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (UserdataPtr)))
|
||||||
|
UserdataPtr (const_cast <void*> (p));
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, key);
|
||||||
|
// If this goes off it means you forgot to register the class!
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit UserdataPtr (void* const p)
|
||||||
|
{
|
||||||
|
m_p = p;
|
||||||
|
|
||||||
|
// Can't construct with a null pointer!
|
||||||
|
//
|
||||||
|
assert (m_p != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** Push non-const pointer to object.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static inline void push (lua_State* const L, T* const p)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
push (L, p, ClassInfo <T>::getClassKey ());
|
||||||
|
else
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Push const pointer to object.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static inline void push (lua_State* const L, T const* const p)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
push (L, p, ClassInfo <T>::getConstKey ());
|
||||||
|
else
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
/**
|
||||||
|
Wraps a container thet references a class object.
|
||||||
|
|
||||||
|
The template argument C is the container type, ContainerTraits must be
|
||||||
|
specialized on C or else a compile error will result.
|
||||||
|
*/
|
||||||
|
template <class C>
|
||||||
|
class UserdataShared : public Userdata
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
UserdataShared (UserdataShared <C> const&);
|
||||||
|
UserdataShared <C>& operator= (UserdataShared <C> const&);
|
||||||
|
|
||||||
|
typedef typename TypeTraits::removeConst <
|
||||||
|
typename ContainerTraits <C>::Type>::Type T;
|
||||||
|
|
||||||
|
C m_c;
|
||||||
|
|
||||||
|
private:
|
||||||
|
~UserdataShared ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
Construct from a container to the class or a derived class.
|
||||||
|
*/
|
||||||
|
template <class U>
|
||||||
|
explicit UserdataShared (U const& u) : m_c (u)
|
||||||
|
{
|
||||||
|
m_p = const_cast <void*> (reinterpret_cast <void const*> (
|
||||||
|
(ContainerTraits <C>::get (m_c))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Construct from a pointer to the class or a derived class.
|
||||||
|
*/
|
||||||
|
template <class U>
|
||||||
|
explicit UserdataShared (U* u) : m_c (u)
|
||||||
|
{
|
||||||
|
m_p = const_cast <void*> (reinterpret_cast <void const*> (
|
||||||
|
(ContainerTraits <C>::get (m_c))));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SFINAE helpers.
|
||||||
|
//
|
||||||
|
|
||||||
|
// non-const objects
|
||||||
|
template <class C, bool makeObjectConst>
|
||||||
|
struct UserdataSharedHelper
|
||||||
|
{
|
||||||
|
typedef typename TypeTraits::removeConst <
|
||||||
|
typename ContainerTraits <C>::Type>::Type T;
|
||||||
|
|
||||||
|
static void push (lua_State* L, C const& c)
|
||||||
|
{
|
||||||
|
if (ContainerTraits <C>::get (c) != 0)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (UserdataShared <C>))) UserdataShared <C> (c);
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <T>::getClassKey ());
|
||||||
|
// If this goes off it means the class T is unregistered!
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void push (lua_State* L, T* const t)
|
||||||
|
{
|
||||||
|
if (t)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (UserdataShared <C>))) UserdataShared <C> (t);
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <T>::getClassKey ());
|
||||||
|
// If this goes off it means the class T is unregistered!
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// const objects
|
||||||
|
template <class C>
|
||||||
|
struct UserdataSharedHelper <C, true>
|
||||||
|
{
|
||||||
|
typedef typename TypeTraits::removeConst <
|
||||||
|
typename ContainerTraits <C>::Type>::Type T;
|
||||||
|
|
||||||
|
static void push (lua_State* L, C const& c)
|
||||||
|
{
|
||||||
|
if (ContainerTraits <C>::get (c) != 0)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (UserdataShared <C>))) UserdataShared <C> (c);
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <T>::getConstKey ());
|
||||||
|
// If this goes off it means the class T is unregistered!
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void push (lua_State* L, T* const t)
|
||||||
|
{
|
||||||
|
if (t)
|
||||||
|
{
|
||||||
|
new (lua_newuserdata (L, sizeof (UserdataShared <C>))) UserdataShared <C> (t);
|
||||||
|
lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <T>::getConstKey ());
|
||||||
|
// If this goes off it means the class T is unregistered!
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil (L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Pass by container.
|
||||||
|
|
||||||
|
The container controls the object lifetime. Typically this will be a
|
||||||
|
lifetime shared by C++ and Lua using a reference count. Because of type
|
||||||
|
erasure, containers like std::shared_ptr will not work. Containers must
|
||||||
|
either be of the intrusive variety, or in the style of the RefCountedPtr
|
||||||
|
type provided by LuaBridge (that uses a global hash table).
|
||||||
|
*/
|
||||||
|
template <class C, bool byContainer>
|
||||||
|
struct StackHelper
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, C const& c)
|
||||||
|
{
|
||||||
|
UserdataSharedHelper <C,
|
||||||
|
TypeTraits::isConst <typename ContainerTraits <C>::Type>::value>::push (L, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef typename TypeTraits::removeConst <
|
||||||
|
typename ContainerTraits <C>::Type>::Type T;
|
||||||
|
|
||||||
|
static inline C get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return Userdata::get <T> (L, index, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Pass by value.
|
||||||
|
|
||||||
|
Lifetime is managed by Lua. A C++ function which accesses a pointer or
|
||||||
|
reference to an object outside the activation record in which it was
|
||||||
|
retrieved may result in undefined behavior if Lua garbage collected it.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
struct StackHelper <T, false>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, T const& t)
|
||||||
|
{
|
||||||
|
UserdataValue <T>::push (L, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline T const& get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return *Userdata::get <T> (L, index, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
Lua stack conversions for class objects passed by value.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
struct Stack
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static inline void push (lua_State* L, T const& t)
|
||||||
|
{
|
||||||
|
StackHelper <T,
|
||||||
|
TypeTraits::isContainer <T>::value>::push (L, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline T get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return StackHelper <T,
|
||||||
|
TypeTraits::isContainer <T>::value>::get (L, index);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
Lua stack conversions for pointers and references to class objects.
|
||||||
|
|
||||||
|
Lifetime is managed by C++. Lua code which remembers a reference to the
|
||||||
|
value may result in undefined behavior if C++ destroys the object. The
|
||||||
|
handling of the const and volatile qualifiers happens in UserdataPtr.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// pointer
|
||||||
|
template <class T>
|
||||||
|
struct Stack <T*>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, T* const p)
|
||||||
|
{
|
||||||
|
UserdataPtr::push (L, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline T* const get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return Userdata::get <T> (L, index, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Strips the const off the right side of *
|
||||||
|
template <class T>
|
||||||
|
struct Stack <T* const>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, T* const p)
|
||||||
|
{
|
||||||
|
UserdataPtr::push (L, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline T* const get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return Userdata::get <T> (L, index, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// pointer to const
|
||||||
|
template <class T>
|
||||||
|
struct Stack <T const*>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, T const* const p)
|
||||||
|
{
|
||||||
|
UserdataPtr::push (L, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline T const* const get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return Userdata::get <T> (L, index, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Strips the const off the right side of *
|
||||||
|
template <class T>
|
||||||
|
struct Stack <T const* const>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, T const* const p)
|
||||||
|
{
|
||||||
|
UserdataPtr::push (L, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline T const* const get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return Userdata::get <T> (L, index, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// reference
|
||||||
|
template <class T>
|
||||||
|
struct Stack <T&>
|
||||||
|
{
|
||||||
|
static inline void push (lua_State* L, T& t)
|
||||||
|
{
|
||||||
|
UserdataPtr::push (L, &t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static T& get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
T* const t = Userdata::get <T> (L, index, false);
|
||||||
|
if (!t)
|
||||||
|
luaL_error (L, "nil passed to reference");
|
||||||
|
return *t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class C, bool byContainer>
|
||||||
|
struct RefStackHelper
|
||||||
|
{
|
||||||
|
typedef C return_type;
|
||||||
|
|
||||||
|
static inline void push (lua_State* L, C const& t)
|
||||||
|
{
|
||||||
|
UserdataSharedHelper <C,
|
||||||
|
TypeTraits::isConst <typename ContainerTraits <C>::Type>::value>::push (L, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef typename TypeTraits::removeConst <
|
||||||
|
typename ContainerTraits <C>::Type>::Type T;
|
||||||
|
|
||||||
|
static return_type get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return Userdata::get <T> (L, index, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct RefStackHelper <T, false>
|
||||||
|
{
|
||||||
|
typedef T const& return_type;
|
||||||
|
|
||||||
|
static inline void push (lua_State* L, T const& t)
|
||||||
|
{
|
||||||
|
UserdataPtr::push (L, &t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static return_type get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
T const* const t = Userdata::get <T> (L, index, true);
|
||||||
|
|
||||||
|
if (!t)
|
||||||
|
luaL_error (L, "nil passed to reference");
|
||||||
|
return *t;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// reference to const
|
||||||
|
template <class T>
|
||||||
|
struct Stack <T const&>
|
||||||
|
{
|
||||||
|
typedef RefStackHelper <T, TypeTraits::isContainer <T>::value> helper_t;
|
||||||
|
|
||||||
|
static inline void push (lua_State* L, T const& t)
|
||||||
|
{
|
||||||
|
helper_t::push (L, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static typename helper_t::return_type get (lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return helper_t::get (L, index);
|
||||||
|
}
|
||||||
|
};
|
28
src/lib/lua/bridge/detail/dump.h
Normal file
28
src/lib/lua/bridge/detail/dump.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string dumpLuaState(lua_State *L) {
|
||||||
|
std::stringstream ostr;
|
||||||
|
int i;
|
||||||
|
int top = lua_gettop(L);
|
||||||
|
ostr << "top=" << top << ":\n";
|
||||||
|
for (i = 1; i <= top; ++i) {
|
||||||
|
int t = lua_type(L, i);
|
||||||
|
switch(t) {
|
||||||
|
case LUA_TSTRING:
|
||||||
|
ostr << " " << i << ": '" << lua_tostring(L, i) << "'\n";
|
||||||
|
break;
|
||||||
|
case LUA_TBOOLEAN:
|
||||||
|
ostr << " " << i << ": " <<
|
||||||
|
(lua_toboolean(L, i) ? "true" : "false") << "\n";
|
||||||
|
break;
|
||||||
|
case LUA_TNUMBER:
|
||||||
|
ostr << " " << i << ": " << lua_tonumber(L, i) << "\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ostr << " " << i << ": TYPE=" << lua_typename(L, t) << "\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ostr.str();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user