Skip to content

Commit

Permalink
Separate out template function implementations due to circular depend…
Browse files Browse the repository at this point in the history
…ency on Lua class

#Co-authored-by: UE4SS <[email protected]>
  • Loading branch information
narknon committed Aug 30, 2024
1 parent 23df328 commit 71fad07
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 44 deletions.
55 changes: 11 additions & 44 deletions deps/first/LuaMadeSimple/include/LuaMadeSimple/LuaMadeSimple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,55 +32,22 @@ namespace RC::LuaMadeSimple
{
const class Lua* lua{};

[[nodiscard]] auto is_nil() -> bool
{
return lua_isnil(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto is_nil() -> bool;

[[nodiscard]] auto is_string() const -> bool
{
return lua_type(lua->get_lua_state(), StackIndex) == LUA_TSTRING;
}
[[nodiscard]] auto get_string() const -> std::string_view
{
return lua_tostring(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto is_string() const -> bool;
[[nodiscard]] auto get_string() const -> std::string_view;

[[nodiscard]] auto is_number() const -> bool
{
return lua_isnumber(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto get_number() const -> double
{
return lua_tonumber(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto get_float(int32_t force_index = 1) -> float // Safe to use after a call to is_number
{
return static_cast<float>(lua_tonumber(lua->get_lua_state(), force_index));
}
[[nodiscard]] auto is_number() const -> bool;
[[nodiscard]] auto get_number() const -> double;
[[nodiscard]] auto get_float(int32_t force_index = 1) -> float; // Safe to use after a call to is_number

[[nodiscard]] auto is_integer() const -> bool
{
return lua_isinteger(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto get_integer() const -> int64_t
{
return lua_tointeger(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto is_integer() const -> bool;
[[nodiscard]] auto get_integer() const -> int64_t;

[[nodiscard]] auto is_bool() const -> bool
{
return lua_isboolean(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto get_bool() const -> bool
{
return lua_toboolean(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto is_bool() const -> bool;
[[nodiscard]] auto get_bool() const -> bool;

[[nodiscard]] auto is_table() const -> bool
{
return lua_istable(lua->get_lua_state(), StackIndex);
}
[[nodiscard]] auto is_table() const -> bool;
};

/**
Expand Down
112 changes: 112 additions & 0 deletions deps/first/LuaMadeSimple/src/LuaMadeSimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,118 @@ namespace RC::LuaMadeSimple
// Current errors for all lua states
static std::unordered_map<lua_State*, std::string> lua_state_errors;

template <>
auto LuaTableData<-1>::is_nil() -> bool
{
return lua_isnil(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::is_string() const -> bool
{
return lua_type(lua->get_lua_state(), -1) == LUA_TSTRING;
}
template <>
auto LuaTableData<-1>::get_string() const -> std::string_view
{
return lua_tostring(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::is_number() const -> bool
{
return lua_isnumber(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::get_number() const -> double
{
return lua_tonumber(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::get_float(int32_t force_index) -> float // Safe to use after a call to is_number
{
return static_cast<float>(lua_tonumber(lua->get_lua_state(), force_index));
}
template <>
auto LuaTableData<-1>::is_integer() const -> bool
{
return lua_isinteger(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::get_integer() const -> int64_t
{
return lua_tointeger(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::is_bool() const -> bool
{
return lua_isboolean(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::get_bool() const -> bool
{
return lua_toboolean(lua->get_lua_state(), -1);
}
template <>
auto LuaTableData<-1>::is_table() const -> bool
{
return lua_istable(lua->get_lua_state(), -1);
}

template <>
auto LuaTableData<-2>::is_nil() -> bool
{
return lua_isnil(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::is_string() const -> bool
{
return lua_type(lua->get_lua_state(), -2) == LUA_TSTRING;
}
template <>
auto LuaTableData<-2>::get_string() const -> std::string_view
{
return lua_tostring(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::is_number() const -> bool
{
return lua_isnumber(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::get_number() const -> double
{
return lua_tonumber(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::get_float(int32_t force_index) -> float // Safe to use after a call to is_number
{
return static_cast<float>(lua_tonumber(lua->get_lua_state(), force_index));
}
template <>
auto LuaTableData<-2>::is_integer() const -> bool
{
return lua_isinteger(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::get_integer() const -> int64_t
{
return lua_tointeger(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::is_bool() const -> bool
{
return lua_isboolean(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::get_bool() const -> bool
{
return lua_toboolean(lua->get_lua_state(), -2);
}
template <>
auto LuaTableData<-2>::is_table() const -> bool
{
return lua_istable(lua->get_lua_state(), -2);
}

Lua::Lua(lua_State* lua_state) : m_lua_state(lua_state), m_registry(*this)
{
}
Expand Down

0 comments on commit 71fad07

Please sign in to comment.