forked from ground/ground
groundAddFunctionToStruct interface
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user