1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-22 11:56:42 +00:00

add string array indexing

This commit is contained in:
suchmememanyskill 2021-07-13 15:53:49 +02:00
parent 8c6e70b63d
commit 3c640e23b1
2 changed files with 18 additions and 3 deletions

View file

@ -1,6 +1,7 @@
#include "StringClass.h"
#include "compat.h"
#include "intClass.h"
#include "scriptError.h"
#include <string.h>
char* getStringValue(Variable_t* var) {
@ -57,6 +58,19 @@ ClassFunction(stringBytes) {
return copyVariableToPtr(v);
}
ClassFunction(stringIndexGet) {
u32 len = strlen(caller->string.value);
u32 idx = args[0]->integer.value;
if (len < idx || idx < 0) {
SCRIPT_FATAL_ERR("Index of string out of range");
}
char* a = calloc(1,2);
a[0] = caller->string.value[idx];
return newStringVariablePtr(a, 0, 0);
}
u8 strOneIntArg[] = { IntClass };
u8 oneStringArg[] = { StringClass };
ClassFunctionTableEntry_t stringFunctions[] = {
@ -64,6 +78,7 @@ ClassFunctionTableEntry_t stringFunctions[] = {
{"+", addStringVariables, 1, oneStringArg },
{"len", getStringLength, 0, 0},
{"bytes", stringBytes, 0, 0},
{"get", stringIndexGet, 1, strOneIntArg},
};
Variable_t getStringMember(Variable_t* var, char* memberName) {

View file

@ -208,7 +208,6 @@ Variable_t getGenericFunctionMember(Variable_t* var, char* memberName, ClassFunc
}
}
printScriptError(SCRIPT_FATAL, "Could not find member of class");
return (Variable_t){ 0 };
}
@ -216,8 +215,9 @@ Variable_t* callMemberFunction(Variable_t* var, char* memberName, CallArgs_t* ar
for (u32 i = 0; i < ARRAY_SIZE(memberGetters); i++) {
if (var->variableType == memberGetters[i].classType) {
Variable_t funcRef = memberGetters[i].func(var, memberName);
if (funcRef.variableType == None)
return NULL;
if (funcRef.variableType == None) {
SCRIPT_FATAL_ERR("Did not find member '%s'", memberName);
}
Variable_t* ptr = &funcRef;
if (funcRef.variableType == ReferenceType) {