// https://github.com/vinniefalco/LuaBridge // // Copyright 2018, Dmitry Tarakanov // SPDX-License-Identifier: MIT #pragma once #include #include namespace luabridge { template struct Stack > { static void push(lua_State* L, std::list const& list) { lua_createtable (L, static_cast (list.size ()), 0); typename std::list ::const_iterator item = list.begin(); for (std::size_t i = 1; i <= list.size (); ++i) { lua_pushinteger (L, static_cast (i)); Stack ::push (L, *item); lua_settable (L, -3); ++item; } } static std::list get(lua_State* L, int index) { if (!lua_istable(L, index)) { luaL_error(L, "#%d argments must be table", index); } std::list list; int const absindex = lua_absindex (L, index); lua_pushnil (L); while (lua_next (L, absindex) != 0) { list.push_back (Stack ::get (L, -1)); lua_pop (L, 1); } return list; } }; template struct Stack const&> : Stack > { }; } // namespace luabridge