Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Dec 25, 2024
1 parent 2ddb42c commit 445e1bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
30 changes: 6 additions & 24 deletions Quake/ls_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "lua.hpp"

extern "C"
{
#include "q_stdinc.h"
#include "cvar.h"
}

class LS_TempAllocatorBase
{
protected:
Expand Down Expand Up @@ -121,32 +115,20 @@ class LS_UserDataType : public LS_TypelessUserDataType
}
};

typedef struct cvar_s cvar_t;
int LS_BoolCVarFunction(lua_State* state, cvar_t& cvar);
int LS_NumberCVarFunction(lua_State* state, cvar_t& cvar);

template <cvar_t& cvar>
inline int LS_BoolCVarFunction(lua_State* state)
{
if (lua_gettop(state) >= 1)
{
const int value = lua_toboolean(state, 1);
Cvar_SetValueQuick(&cvar, static_cast<float>(value));
return 0;
}

lua_pushboolean(state, static_cast<int>(cvar.value));
return 1;
return LS_BoolCVarFunction(state, cvar);
}

template <cvar_t& cvar>
inline int LS_NumberCVarFunction(lua_State* state)
{
if (lua_gettop(state) >= 1)
{
const float value = luaL_checknumber(state, 1);
Cvar_SetValueQuick(&cvar, value);
return 0;
}

lua_pushnumber(state, cvar.value);
return 1;
return LS_NumberCVarFunction(state, cvar);
}

void LS_InitEdictType(lua_State* state);
Expand Down
27 changes: 27 additions & 0 deletions Quake/ls_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,33 @@ void LS_TypelessUserDataType::SetMetaTable(lua_State* state, const luaL_Reg* mem
}


int LS_BoolCVarFunction(lua_State* state, cvar_t& cvar)
{
if (lua_gettop(state) >= 1)
{
const int value = lua_toboolean(state, 1);
Cvar_SetValueQuick(&cvar, static_cast<float>(value));
return 0;
}

lua_pushboolean(state, static_cast<int>(cvar.value));
return 1;
}

int LS_NumberCVarFunction(lua_State* state, cvar_t& cvar)
{
if (lua_gettop(state) >= 1)
{
const float value = luaL_checknumber(state, 1);
Cvar_SetValueQuick(&cvar, value);
return 0;
}

lua_pushnumber(state, cvar.value);
return 1;
}


//
// Expose 'player' global table with corresponding helper functions
//
Expand Down

0 comments on commit 445e1bd

Please sign in to comment.