?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. // https://github.com/vinniefalco/LuaBridge
  2. // Copyright 2020, Dmitry Tarakanov
  3. // SPDX-License-Identifier: MIT
  4.  
  5. #pragma once
  6.  
  7. #include <LuaBridge/detail/Stack.h>
  8.  
  9. #include <list>
  10.  
  11. namespace luabridge {
  12.  
  13. template<class T>
  14. struct Stack<std::list<T>>
  15. {
  16.     static void push(lua_State* L, std::list<T> const& list)
  17.     {
  18.         lua_createtable(L, static_cast<int>(list.size()), 0);
  19.         typename std::list<T>::const_iterator item = list.begin();
  20.         for (std::size_t i = 1; i <= list.size(); ++i)
  21.         {
  22.             lua_pushinteger(L, static_cast<lua_Integer>(i));
  23.             Stack<T>::push(L, *item);
  24.             lua_settable(L, -3);
  25.             ++item;
  26.         }
  27.     }
  28.  
  29.     static std::list<T> get(lua_State* L, int index)
  30.     {
  31.         if (!lua_istable(L, index))
  32.         {
  33.             luaL_error(L, "#%d argument must be a table", index);
  34.         }
  35.  
  36.         std::list<T> list;
  37.  
  38.         int const absindex = lua_absindex(L, index);
  39.         lua_pushnil(L);
  40.         while (lua_next(L, absindex) != 0)
  41.         {
  42.             list.push_back(Stack<T>::get(L, -1));
  43.             lua_pop(L, 1);
  44.         }
  45.         return list;
  46.     }
  47.  
  48.     static bool isInstance(lua_State* L, int index) { return lua_istable(L, index); }
  49. };
  50.  
  51. } // namespace luabridge
  52.