Update LuaBridge to e3f7a022
parent
023ead937f
commit
1f2349ef6e
@ -0,0 +1,55 @@
|
||||
// https://github.com/vinniefalco/LuaBridge
|
||||
//
|
||||
// Copyright 2018, Dmitry Tarakanov
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LuaBridge/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 <LuaBridge/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 <LuaBridge/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