X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fnasal.h;h=832724471ffdd3e340945008d84204500dfde976;hb=e5acc3f0482caea19e9c7873271758153d56aef8;hp=db7354eab327e6634ca581d91bcf5a9c00464672;hpb=3da44d1215fe5c35c7650aa5815d1b2c5b67d569;p=simgear.git diff --git a/simgear/nasal/nasal.h b/simgear/nasal/nasal.h index db7354ea..83272447 100644 --- a/simgear/nasal/nasal.h +++ b/simgear/nasal/nasal.h @@ -42,10 +42,25 @@ naContext naSubContext(naContext super); void naSetUserData(naContext c, void* p); void* naGetUserData(naContext c) GCC_PURE; +// run GC now (may block) +void naGC(); + // "Save" this object in the context, preventing it (and objects // referenced by it) from being garbage collected. +// TODO do we need a context? It is not used anyhow... void naSave(naContext ctx, naRef obj); +// "Save" this object and get a key which allows do mark the object as free +// later on (with naGCFree). +int naGCSave(naRef obj); + +// Release an object previously passed to naGCSave to allow it being cleaned up +// by the garbage collector. +void naGCRelease(int key); + +// Drop all saved references +void naClearSaved(); + // 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. @@ -88,6 +103,28 @@ naRef naCall(naContext ctx, naRef func, int argc, naRef* args, // naModUnlock() first if the lock is already held. naRef naContinue(naContext ctx); +// Does a naCall() in a given context. Wrapped here to make lock +// tracking easier. Extension functions are called with the lock, but +// we have to release it before making a new naCall(). So rather than +// drop the lock in every extension function that might call back into +// Nasal, we keep a stack depth counter here and only unlock/lock +// around the naCall if it isn't the first one. +naRef naCallMethodCtx( naContext ctx, + naRef code, + naRef self, + int argc, + naRef* args, + naRef locals ); + +// Same as naCallMethodCtx but creates (and afterwards destroyes) a new context +naRef naCallMethod(naRef code, naRef self, int argc, naRef* args, naRef locals); + +typedef void (*naErrorHandler)(naContext); + +// Register a handler to be called if an error is raised during the execution of +// naCallMethodCtx or naCallMethod. +naErrorHandler naSetErrorHandler(naErrorHandler cb); + // 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 // intended for use in library code that cannot otherwise report an @@ -143,6 +180,9 @@ int naIsCode(naRef r) GCC_PURE; int naIsFunc(naRef r) GCC_PURE; int naIsCCode(naRef r) GCC_PURE; +// Object equality (check for same instance, aka. pointer equality) +int naIsIdentical(naRef l, naRef r) GCC_PURE; + // Allocators/generators: naRef naNil() GCC_PURE; naRef naNum(double num) GCC_PURE;