Allow strings to be returned from structs
All checks were successful
Build Dusk / run-tests (push) Successful in 1m33s
Build Dusk / build-linux (push) Successful in 1m53s
Build Dusk / build-psp (push) Successful in 1m51s

This commit is contained in:
2026-01-28 18:34:23 -06:00
parent 794e0574ad
commit c2cad858a5
6 changed files with 12 additions and 9 deletions

View File

@@ -9,6 +9,7 @@
#include "assert/assert.h"
#include "script/struct/scriptstruct.h"
#include "util/string.h"
#include "util/memory.h"
void moduleGLM(scriptcontext_t *context) {
assertNotNull(context, "Context cannot be NULL.");
@@ -32,6 +33,8 @@ void moduleGLMVec3Getter(
assertNotNull(structPtr, "Structure pointer cannot be NULL.");
assertNotNull(outValue, "Output value cannot be NULL.");
printf("Getting vec3 field %s\n", key);
vec3 *v = (vec3 *)structPtr;
if(stringCompare(key, "x") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;

View File

@@ -21,7 +21,7 @@ typedef struct scriptvalue_s {
union {
int32_t intValue;
float_t floatValue;
const char_t *strValue;
char_t *strValue;
bool_t boolValue;
} value;
} scriptvalue_t;

View File

@@ -7,6 +7,7 @@
#include "scriptstruct.h"
#include "assert/assert.h"
#include "util/memory.h"
void scriptStructRegister(
scriptcontext_t *context,
@@ -66,7 +67,9 @@ int scriptStructIndex(lua_State *l) {
break;
case SCRIPT_VALUE_TYPE_STRING:
assertNotNull(outValue.value.strValue, "String value cannot be NULL");
lua_pushstring(l, outValue.value.strValue);
memoryFree((void *)outValue.value.strValue);
break;
case SCRIPT_VALUE_TYPE_BOOL:
@@ -122,6 +125,7 @@ int scriptStructNewIndex(lua_State *l) {
inValue.type = SCRIPT_VALUE_TYPE_BOOL;
inValue.value.boolValue = lua_toboolean(l, 3);
break;
case LUA_TNIL:
inValue.type = SCRIPT_VALUE_TYPE_NIL;
break;