Skip to content

Commit

Permalink
finalize building of lua edict table
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Aug 5, 2023
1 parent 93a0088 commit e32abf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 6 additions & 7 deletions Quake/lua_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "quakedef.h"


qboolean ED_GetFieldByIndex(edict_t* ed, size_t fieldindex, etype_t* type, const char** name, const eval_t** value);
const char* ED_GetFieldNameByOffset(int offset);

static const char* LUA_axisnames[] = { "x", "y", "z" };

static int LUA_Vec3String(lua_State* state)
Expand Down Expand Up @@ -69,16 +72,13 @@ static qboolean LUA_MakeEdictTable(lua_State* state, int index)
const char* name;
const eval_t* value;

extern qboolean ED_GetFieldAt(edict_t* ed, size_t fieldindex, etype_t* type, const char** name, const eval_t** value);
if (!ED_GetFieldAt(ed, fi, &type, &name, &value))
if (!ED_GetFieldByIndex(ed, fi, &type, &name, &value))
continue;

assert(type != ev_bad);
assert(name);
assert(value);

dfunction_t* func;

switch (type)
{
case ev_string:
Expand Down Expand Up @@ -111,12 +111,11 @@ static qboolean LUA_MakeEdictTable(lua_State* state, int index)
break;

case ev_field:
lua_pushfstring(state, ".%s", "_TODO_");
lua_pushfstring(state, ".%s", ED_GetFieldNameByOffset(value->_int));
break;

case ev_function:
func = pr_functions + value->function;
lua_pushfstring(state, "%s()", PR_GetString(func->s_name));
lua_pushfstring(state, "%s()", PR_GetString((pr_functions + value->function)->s_name));
break;

case ev_pointer:
Expand Down
8 changes: 7 additions & 1 deletion Quake/pr_edict.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ int PR_AllocString (int size, char **ptr)
}


qboolean ED_GetFieldAt(edict_t* ed, size_t fieldindex, etype_t* type, const char** name, const eval_t** value)
qboolean ED_GetFieldByIndex(edict_t* ed, size_t fieldindex, etype_t* type, const char** name, const eval_t** value)
{
if (fieldindex >= (size_t)progs->numfielddefs)
return false;
Expand Down Expand Up @@ -1614,3 +1614,9 @@ qboolean ED_GetFieldAt(edict_t* ed, size_t fieldindex, etype_t* type, const char

return true;
}

const char* ED_GetFieldNameByOffset(int offset)
{
const ddef_t* def = ED_FieldAtOfs(offset);
return def ? PR_GetString(def->s_name) : "";
}

0 comments on commit e32abf7

Please sign in to comment.