?login_element?

Subversion Repositories NedoOS

Rev

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

  1. // https://github.com/vinniefalco/LuaBridge
  2. // Copyright 2021, Stefan Frings
  3. // SPDX-License-Identifier: MIT
  4.  
  5. #pragma once
  6.  
  7. #include <LuaBridge/detail/Stack.h>
  8.  
  9. #include <optional>
  10.  
  11. namespace luabridge {
  12.  
  13. template<class T>
  14. struct Stack<std::optional<T>>
  15. {
  16.     static void push(lua_State* L, std::optional<T> const& optional)
  17.     {
  18.         if (optional)
  19.         {
  20.             Stack<T>::push(L, *optional);
  21.         }
  22.         else
  23.         {
  24.             lua_pushnil(L);
  25.         }
  26.     }
  27.  
  28.     static std::optional<T> get(lua_State* L, int index)
  29.     {
  30.         if (lua_isnil(L, index))
  31.         {
  32.             lua_pop(L, 1);
  33.  
  34.             return std::nullopt;
  35.         }
  36.  
  37.         return Stack<T>::get(L, index);
  38.     }
  39.  
  40.     static bool isInstance(lua_State* L, int index)
  41.     {
  42.         return lua_isnil(L, index) || Stack<T>::isInstance(L, index);
  43.     }
  44. };
  45.  
  46. } // namespace luabridge
  47.