// 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::vector const& vector) { lua_createtable (L, static_cast (vector.size ()), 0); for (std::size_t i = 0; i < vector.size (); ++i) { lua_pushinteger (L, static_cast (i + 1)); Stack ::push (L, vector [i]); lua_settable (L, -3); } } static std::vector get(lua_State* L, int index) { if (!lua_istable(L, index)) { luaL_error(L, "#%d argments must be table", index); } std::vector vector; vector.reserve (static_cast (get_length (L, index))); int const absindex = lua_absindex (L, index); lua_pushnil (L); while (lua_next (L, absindex) != 0) { vector.push_back (Stack ::get (L, -1)); lua_pop (L, 1); } return vector; } }; template struct Stack const&> : Stack > { }; } // namespace luabridge