groundAddFunctionToStruct interface

This commit is contained in:
2026-04-11 12:18:57 +10:00
parent 6f6239f495
commit fcf9a13fa1
2 changed files with 22 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ typedef GroundValue (*NativeGroundFunction)(GroundScope* scope, List args);
* ...: A sequence of (GroundValueType type, char* name) for each argument.
*/
void groundAddNativeFunction(GroundScope* scope, char* name, NativeGroundFunction fn, GroundValueType returnType, int argCount, ...);
void groundAddFunctionToStruct(GroundStruct* gstruct, char* name, NativeGroundFunction fn, GroundValueType returnType, int argCount, ...);
#ifdef __cplusplus
}

View File

@@ -151,6 +151,27 @@ void groundAddValueToScope(GroundScope* gs, const char* name, GroundValue value)
void groundAddFieldToStruct(GroundStruct* gstruct, char* name, GroundValue field) {
addFieldToStruct(gstruct, name, field);
}
GroundFunction* createGroundFunction();
void addArgsToGroundFunction(GroundFunction* function, GroundValueType type, char* name);
void groundAddFunctionToStruct(GroundStruct* gstruct, char* name, NativeGroundFunction fn, GroundValueType returnType, int argCount, ...) {
GroundFunction* gf = createGroundFunction();
gf->isNative = true;
gf->nativeFn = fn;
gf->returnType = returnType;
va_list args;
va_start(args, argCount);
for(int i = 0; i < argCount; i++) {
GroundValueType type = va_arg(args, GroundValueType);
char* argName = va_arg(args, char*);
addArgsToGroundFunction(gf, type, argName);
}
va_end(args);
GroundValue gv = createFunctionGroundValue(gf);
addFieldToStruct(gstruct, name, gv);
}
void groundCompileProgram(GroundProgram* program) {
compileGroundProgram(program, "program.gexe");