Files
cground/include/groundext.h

58 lines
1.6 KiB
C
Raw Normal View History

2026-01-02 20:56:00 +11:00
#ifndef GROUND_EXT_H
#define GROUND_EXT_H
#include "groundvm.h"
#ifdef __cplusplus
extern "C" {
#endif
2026-01-19 19:29:14 +11:00
// Macro for easily returning errors
#define ERROR(what, type) return createErrorGroundValue(createGroundError(what, type, NULL, NULL))
2026-01-02 20:56:00 +11:00
// Forward declaration of the scope structure used in interpreter
struct GroundScope;
typedef struct GroundScope GroundScope;
2026-01-19 19:29:14 +11:00
/*
* Stores data associated with an error thrown during Ground execution.
*/
typedef struct GroundError {
char* what;
char* type;
struct GroundInstruction* where;
size_t line;
bool hasLine;
} GroundError;
// Creates a GroundValue containing (in), with type ERROR.
GroundValue createErrorGroundValue(GroundError in);
// Creates a GroundError.
GroundError createGroundError(char* what, char* type, GroundInstruction* where, size_t* line);
2026-01-02 20:56:00 +11:00
/*
* Function pointer type for native functions.
* scope: The current execution scope (opaque).
* args: A List of arguments passed to the function.
*/
typedef GroundValue (*NativeGroundFunction)(GroundScope* scope, List args);
/*
* Registers a native function in the given scope.
*
* scope: The scope to register the function in.
* name: The name of the function in Ground.
* fn: The C function to call.
* returnType: The return type of the function.
* argCount: The number of arguments the function expects.
* ...: A sequence of (GroundValueType type, char* name) for each argument.
*/
void groundAddNativeFunction(GroundScope* scope, char* name, NativeGroundFunction fn, GroundValueType returnType, int argCount, ...);
#ifdef __cplusplus
}
#endif
#endif