diff options
| author | 2025-04-11 20:47:52 +0200 | |
|---|---|---|
| committer | 2025-04-11 20:47:52 +0200 | |
| commit | ae4c0b047ab46addeccdbab828fb81a766db5db3 (patch) | |
| tree | eff60bdfafef0fa713381e477ba58fe26219d66f /pez.h | |
| parent | ef06c98e90ef97110594f2f1a457a7b68438774c (diff) | |
basic C user data, io
Diffstat (limited to 'pez.h')
| -rw-r--r-- | pez.h | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -19,7 +19,8 @@ enum { PEZ_TTuple, PEZ_TRecord, PEZ_TArray, - PEZ_TDilambda + PEZ_TDilambda, + PEZ_TUserObj, }; typedef enum PezError { @@ -29,12 +30,17 @@ typedef enum PezError { PEZ_ERuntime, } PezError; - typedef struct PezContext PezContext; typedef void *PezAllocFn(void *userdata, void *ptr, size_t oldsize, size_t newsize); typedef bool PezCFn(PezContext *, int argc); typedef int PezReadFn(void *userdata, char *dst, int n); +typedef struct PezUserType { + const char *name; + size_t size; + void (*dtor)(void *); +} PezUserType; + PezContext *pez_new(PezAllocFn *alloc, void *userdata, size_t stacksize); void pez_del(PezContext *); @@ -63,6 +69,7 @@ bool pez_pushnumber(PezContext *, PezNumber); bool pez_pushint(PezContext *, int); bool pez_pushstring(PezContext *, const char *str, int len); bool pez_pushglobal(PezContext *, const char *name); +bool pez_pushuserobj(PezContext *, const PezUserType *, void *data); bool pez_isvoid(PezContext *, int idx); bool pez_isnumber(PezContext *, int idx); @@ -70,6 +77,7 @@ bool pez_isbool(PezContext *, int idx); bool pez_isstring(PezContext *, int idx); bool pez_isfunction(PezContext *, int idx); bool pez_isarray(PezContext *, int idx); +bool pez_isuserobj(PezContext *, const PezUserType *, int idx); bool pez_truthy(PezContext *, int idx); int pez_typeof(PezContext *, int idx); const char *pez_typename(PezContext *, int idx); @@ -79,6 +87,7 @@ bool pez_checksig(PezContext *, int argc, const char *fn, const char *sig); bool pez_getnumber(PezContext *, PezNumber *, int idx); bool pez_getbool(PezContext *, bool *, int idx); const char *pez_getstring(PezContext *, char buf[8], int idx); +void *pez_getuserobj(PezContext *cx, const PezUserType *, int idx); const char *pez_fnname(PezContext *, int idx); int pez_length(PezContext *cx, int idx); |