[General] Update LuaBridge to 3154e94487dedc84f038c5787985ddc01a95d126
parent
af228c0539
commit
796717bab0
@ -0,0 +1,41 @@
|
||||
set (LUABRIDGE_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/List.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/LuaBridge.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Map.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/RefCountedObject.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/RefCountedPtr.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Vector.h
|
||||
)
|
||||
source_group ("LuaBridge" FILES ${LUABRIDGE_HEADERS})
|
||||
|
||||
set (LUABRIDGE_DETAIL_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/CFunctions.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/ClassInfo.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/Constructor.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/dump.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/FuncTraits.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/Iterator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/LuaException.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/LuaHelpers.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/LuaRef.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/Namespace.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/Stack.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/TypeList.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/TypeTraits.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/detail/Userdata.h
|
||||
)
|
||||
source_group ("LuaBridge\\detail" FILES ${LUABRIDGE_DETAIL_HEADERS})
|
||||
|
||||
add_library (LuaBridge INTERFACE)
|
||||
target_sources (LuaBridge INTERFACE
|
||||
${LUABRIDGE_HEADERS}
|
||||
${LUABRIDGE_DETAIL_HEADERS}
|
||||
)
|
||||
target_include_directories (LuaBridge INTERFACE .)
|
||||
|
||||
if (MSVC)
|
||||
add_custom_target (LuaBridgeLibrary SOURCES
|
||||
${LUABRIDGE_HEADERS}
|
||||
${LUABRIDGE_DETAIL_HEADERS}
|
||||
)
|
||||
endif ()
|
@ -0,0 +1,55 @@
|
||||
// https://github.com/vinniefalco/LuaBridge
|
||||
//
|
||||
// Copyright 2018, Dmitry Tarakanov
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <detail/Stack.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace luabridge {
|
||||
|
||||
template <class T>
|
||||
struct Stack <std::list <T> >
|
||||
{
|
||||
static void push(lua_State* L, std::list <T> const& list)
|
||||
{
|
||||
lua_createtable (L, static_cast <int> (list.size ()), 0);
|
||||
typename std::list <T>::const_iterator item = list.begin();
|
||||
for (std::size_t i = 1; i <= list.size (); ++i)
|
||||
{
|
||||
lua_pushinteger (L, static_cast <lua_Integer> (i));
|
||||
Stack <T>::push (L, *item);
|
||||
lua_settable (L, -3);
|
||||
++item;
|
||||
}
|
||||
}
|
||||
|
||||
static std::list <T> get(lua_State* L, int index)
|
||||
{
|
||||
if (!lua_istable(L, index))
|
||||
{
|
||||
luaL_error(L, "#%d argments must be table", index);
|
||||
}
|
||||
|
||||
std::list <T> list;
|
||||
|
||||
int const absindex = lua_absindex (L, index);
|
||||
lua_pushnil (L);
|
||||
while (lua_next (L, absindex) != 0)
|
||||
{
|
||||
list.push_back (Stack <T>::get (L, -1));
|
||||
lua_pop (L, 1);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct Stack <std::list <T> const&> : Stack <std::list <T> >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace luabridge
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@
|
||||
// https://github.com/vinniefalco/LuaBridge
|
||||
//
|
||||
// Copyright 2018, Dmitry Tarakanov
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <detail/Stack.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace luabridge {
|
||||
|
||||
template <class K, class V>
|
||||
struct Stack <std::map <K, V> >
|
||||
{
|
||||
typedef std::map <K, V> Map;
|
||||
|
||||
static void push(lua_State* L, const Map& map)
|
||||
{
|
||||
lua_createtable (L, 0, static_cast <int> (map.size ()));
|
||||
typedef typename Map::const_iterator ConstIter;
|
||||
for (ConstIter i = map.begin(); i != map.end(); ++i)
|
||||
{
|
||||
Stack <K>::push (L, i->first);
|
||||
Stack <V>::push (L, i->second);
|
||||
lua_settable (L, -3);
|
||||
}
|
||||
}
|
||||
|
||||
static Map get(lua_State* L, int index)
|
||||
{
|
||||
if (!lua_istable(L, index))
|
||||
{
|
||||
luaL_error(L, "#%d argments must be table", index);
|
||||
}
|
||||
|
||||
Map map;
|
||||
int const absindex = lua_absindex (L, index);
|
||||
lua_pushnil (L);
|
||||
while (lua_next (L, absindex) != 0)
|
||||
{
|
||||
map.emplace (Stack <K>::get (L, -2), Stack <V>::get (L, -1));
|
||||
lua_pop (L, 1);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
};
|
||||
|
||||
template <class K, class V>
|
||||
struct Stack <std::map <K, V> const&> : Stack <std::map <K, V> >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace luabridge
|
@ -0,0 +1,54 @@
|
||||
// https://github.com/vinniefalco/LuaBridge
|
||||
//
|
||||
// Copyright 2018, Dmitry Tarakanov
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <detail/Stack.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace luabridge {
|
||||
|
||||
template <class T>
|
||||
struct Stack <std::vector <T> >
|
||||
{
|
||||
static void push(lua_State* L, std::vector <T> const& vector)
|
||||
{
|
||||
lua_createtable (L, static_cast <int> (vector.size ()), 0);
|
||||
for (std::size_t i = 0; i < vector.size (); ++i)
|
||||
{
|
||||
lua_pushinteger (L, static_cast <lua_Integer> (i + 1));
|
||||
Stack <T>::push (L, vector [i]);
|
||||
lua_settable (L, -3);
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector <T> get(lua_State* L, int index)
|
||||
{
|
||||
if (!lua_istable(L, index))
|
||||
{
|
||||
luaL_error(L, "#%d argments must be table", index);
|
||||
}
|
||||
|
||||
std::vector <T> vector;
|
||||
vector.reserve (static_cast <std::size_t> (get_length (L, index)));
|
||||
|
||||
int const absindex = lua_absindex (L, index);
|
||||
lua_pushnil (L);
|
||||
while (lua_next (L, absindex) != 0)
|
||||
{
|
||||
vector.push_back (Stack <T>::get (L, -1));
|
||||
lua_pop (L, 1);
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct Stack <std::vector <T> const&> : Stack <std::vector <T> >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace luabridge
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
namespace luabridge {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace luabridge
|
Loading…
Reference in New Issue