From 3da4016d5784adef217fff0ad1e3a0ceff76290f Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 22 Mar 2022 17:15:17 -0700 Subject: Chapter 24.7 --- clox/src/object.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'clox/src/object.h') diff --git a/clox/src/object.h b/clox/src/object.h index 812c464..b5942d6 100644 --- a/clox/src/object.h +++ b/clox/src/object.h @@ -8,14 +8,17 @@ #define OBJ_TYPE(value) (AS_OBJ(value)->type) #define IS_FUNCTION(value) isObjType(value, OBJ_FUNCTION) +#define IS_NATIVE(value) isObjType(value, OBJ_NATIVE) #define IS_STRING(value) isObjType(value, OBJ_STRING) #define AS_FUNCTION(value) ((ObjFunction *)AS_OBJ(value)) +#define AS_NATIVE(value) (((ObjNative *)AS_OBJ(value))->function) #define AS_STRING(value) ((ObjString *)AS_OBJ(value)) #define AS_CSTRING(value) (((ObjString *)AS_OBJ(value))->chars) typedef enum { OBJ_FUNCTION, + OBJ_NATIVE, OBJ_STRING, } ObjType; @@ -31,6 +34,13 @@ typedef struct { ObjString *name; } ObjFunction; +typedef Value (*NativeFn)(int argCount, Value *args); + +typedef struct { + Obj obj; + NativeFn function; +} ObjNative; + struct ObjString { Obj obj; int length; @@ -39,6 +49,7 @@ struct ObjString { }; ObjFunction *newFunction(); +ObjNative *newNative(NativeFn function); ObjString *takeString(char *chars, int length); ObjString *copyString(const char *chars, int length); void printObject(Value value); -- cgit v1.2.3-54-g00ecf