]> git.mxchange.org Git - simgear.git/blobdiff - simgear/nasal/nasal.h
Olaf Flebbe:
[simgear.git] / simgear / nasal / nasal.h
index 85fff9661e4a82c519ae5b2bc042109c7c00e4a1..719183b6eb597d7c7afda8ad748098b97bf3cd8a 100644 (file)
@@ -62,7 +62,6 @@ typedef union {
             struct naHash* hash;
             struct naCode* code;
             struct naFunc* func;
-            struct naClosure* closure;
             struct naCCode* ccode;
             struct naGhost* ghost;
         } ptr;
@@ -75,15 +74,21 @@ typedef union {
 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);
@@ -95,10 +100,14 @@ naRef naParseCode(naContext c, naRef srcFile, int firstLine,
 // 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
@@ -115,8 +124,12 @@ naRef naMethod(naContext ctx, naRef func, naRef object);
 // 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);
@@ -146,6 +159,7 @@ naRef naNewCCode(naContext c, naCFunction fptr);
 
 // 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);
@@ -156,6 +170,7 @@ char* naStr_data(naRef s);
 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);
@@ -183,6 +198,20 @@ naGhostType* naGhost_type(naRef ghost);
 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