struct naHash* hash;
struct naCode* code;
struct naFunc* func;
- struct naClosure* closure;
struct naCCode* ccode;
struct naGhost* ghost;
} ptr;
typedef struct Context* naContext;
// The function signature for an extension function:
-typedef naRef (*naCFunction)(naContext ctx, naRef args);
+typedef naRef (*naCFunction)(naContext ctx, naRef me, int argc, naRef* args);
// All Nasal code runs under the watch of a naContext:
naContext naNewContext();
+void naFreeContext(naContext c);
// Save this object in the context, preventing it (and objects
// referenced by it) from being garbage collected.
void naSave(naContext ctx, naRef obj);
+// Similar, but the object is automatically released when the
+// context next runs native bytecode. Useful for saving off C-space
+// temporaries to protect them before passing back into a naCall.
+void naTempSave(naContext c, naRef r);
+
// Parse a buffer in memory into a code object.
naRef naParseCode(naContext c, naRef srcFile, int firstLine,
char* buf, int len, int* errLine);
// information from function objects.
naRef naBindFunction(naContext ctx, naRef code, naRef closure);
+// Similar, but it binds to the current context's closure (i.e. the
+// namespace at the top of the current call stack).
+naRef naBindToContext(naContext ctx, naRef code);
+
// Call a code or function object with the specifed arguments "on" the
// specified object and using the specified hash for the local
// variables. Any of args, obj or locals may be nil.
-naRef naCall(naContext ctx, naRef func, naRef args, naRef obj, naRef locals);
+naRef naCall(naContext ctx, naRef func, int argc, naRef* args, naRef obj, naRef locals);
// Throw an error from the current call stack. This function makes a
// longjmp call to a handler in naCall() and DOES NOT RETURN. It is
// Useful for passing as a namespace to an initial function call
naRef naStdLib(naContext c);
-// Ditto, with math functions
+// Ditto, for other core libraries
naRef naMathLib(naContext c);
+naRef naBitsLib(naContext c);
+naRef naIOLib(naContext c);
+naRef naRegexLib(naContext c);
+naRef naUnixLib(naContext c);
// Current line number & error message
int naStackDepth(naContext ctx);
// Some useful conversion/comparison routines
int naEqual(naRef a, naRef b);
+int naStrEqual(naRef a, naRef b);
int naTrue(naRef b);
naRef naNumValue(naRef n);
naRef naStringValue(naContext c, naRef n);
naRef naStr_fromdata(naRef dst, char* data, int len);
naRef naStr_concat(naRef dest, naRef s1, naRef s2);
naRef naStr_substr(naRef dest, naRef str, int start, int len);
+naRef naInternSymbol(naRef sym);
// Vector utilities:
int naVec_size(naRef v);
void naVec_set(naRef vec, int i, naRef o);
int naVec_append(naRef vec, naRef o);
naRef naVec_removelast(naRef vec);
+void naVec_setsize(naRef vec, int sz);
// Hash utilities:
int naHash_size(naRef h);
void* naGhost_ptr(naRef ghost);
int naIsGhost(naRef r);
+// Acquires a "modification lock" on a context, allowing the C code to
+// modify Nasal data without fear that such data may be "lost" by the
+// garbage collector (the C stack is not examined in GC!). This
+// disallows garbage collection until the current thread can be
+// blocked. The lock should be acquired whenever modifications to
+// Nasal objects are made. It need not be acquired when only read
+// access is needed. It MUST NOT be acquired by naCFunction's, as
+// those are called with the lock already held; acquiring two locks
+// for the same thread will cause a deadlock when the GC is invoked.
+// It should be UNLOCKED by naCFunction's when they are about to do
+// any long term non-nasal processing and/or blocking I/O.
+void naModLock();
+void naModUnlock();
+
#ifdef __cplusplus
} // extern "C"
#endif