aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LuaBridge/Source/LuaBridge/List.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LuaBridge/Source/LuaBridge/List.h')
-rw-r--r--lib/LuaBridge/Source/LuaBridge/List.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/LuaBridge/Source/LuaBridge/List.h b/lib/LuaBridge/Source/LuaBridge/List.h
new file mode 100644
index 0000000..3969f32
--- /dev/null
+++ b/lib/LuaBridge/Source/LuaBridge/List.h
@@ -0,0 +1,50 @@
+// 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;
+ }
+};
+
+} // namespace luabridge