|
@@ -3,6 +3,9 @@
|
|
|
|
|
|
#include "utils/Functions.h"
|
|
|
|
|
|
+static bool useGlobals = false;
|
|
|
+static Functions globalFunctions;
|
|
|
+
|
|
|
void fInit(Function* f, const char* name, int line) {
|
|
|
f->name = name;
|
|
|
f->arguments = 0;
|
|
@@ -10,6 +13,8 @@ void fInit(Function* f, const char* name, int line) {
|
|
|
f->address = -1;
|
|
|
f->size = 0;
|
|
|
f->line = line;
|
|
|
+ f->global = false;
|
|
|
+ f->scriptFunction = NULL;
|
|
|
}
|
|
|
|
|
|
bool fAddArgument(Function* f, DataType type, Structs* sts) {
|
|
@@ -43,7 +48,7 @@ void fsDelete(Functions* fs) {
|
|
|
free(fs->data);
|
|
|
}
|
|
|
|
|
|
-Function* fsSearch(Functions* fs, Function* f) {
|
|
|
+static Function* fsInternSearch(Functions* fs, Function* f) {
|
|
|
for(int i = 0; i < fs->entries; i++) {
|
|
|
if(fCompare(fs->data + i, f)) {
|
|
|
return fs->data + i;
|
|
@@ -52,10 +57,55 @@ Function* fsSearch(Functions* fs, Function* f) {
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
+Function* fsSearch(Functions* fs, Function* f) {
|
|
|
+ if(useGlobals) {
|
|
|
+ Function* gf = fsInternSearch(&globalFunctions, f);
|
|
|
+ if(gf != NULL) {
|
|
|
+ return gf;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fsInternSearch(fs, f);
|
|
|
+}
|
|
|
+
|
|
|
void fsAdd(Functions* fs, Function* f) {
|
|
|
if(fs->entries >= fs->capacity) {
|
|
|
fs->capacity *= 2;
|
|
|
fs->data = realloc(fs->data, sizeof(Function) * fs->capacity);
|
|
|
}
|
|
|
fs->data[fs->entries++] = *f;
|
|
|
+}
|
|
|
+
|
|
|
+void gfInit(Function* f, const char* name, DataType r, ScriptFunction sf) {
|
|
|
+ fInit(f, name, -1);
|
|
|
+ f->returnType = r;
|
|
|
+ f->scriptFunction = sf;
|
|
|
+}
|
|
|
+
|
|
|
+void gfsInit() {
|
|
|
+ fsInit(&globalFunctions);
|
|
|
+ useGlobals = true;
|
|
|
+}
|
|
|
+
|
|
|
+bool gfsAdd(Function* f) {
|
|
|
+ if(fsSearch(&globalFunctions, f) != NULL) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ int index = globalFunctions.entries;
|
|
|
+ fsAdd(&globalFunctions, f);
|
|
|
+ globalFunctions.data[index].line = index;
|
|
|
+ globalFunctions.data[index].global = true;
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool gfsCall(Script* sc, int id) {
|
|
|
+ if(!useGlobals || id < 0 || id >= globalFunctions.entries) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ globalFunctions.data[id].scriptFunction(sc);
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+void gfsDelete() {
|
|
|
+ fsDelete(&globalFunctions);
|
|
|
+ useGlobals = false;
|
|
|
}
|