Sync with Nasal CVS (soon to become Nasal 1.1). Notable new features:
Nasal now supports calls to "subcontexts" and errors can be thrown across them, leading to complete stack traces when call() is used, instead of the truncated ones we now see. Vectors can now be concatenated using the ~ operator that used to work only for strings. Better runtime error messages in general due to a fancier naRuntimeError() implementation A big data size shrink on 64 bit systems; the size of a naRef dropped by a factor of two. "Braceless code blocks" have been added to the parser, so you can write expressions like "if(a) b();" just like in C. Note that there's still a parser bug in there that fails when you nest a braced block within a braceless one. Character constants that appear in Nasal source code can now be literal multibyte UTF8 characters (this was always supported for string literals, but character constants were forced to be a single byte). New modules: "bits", "thread", "utf8" and (gulp...) "io". The bits library might be useful to FlightGear, the utf8 one probably not as Plib does not support wide character text rendering. The thread library will work fine for spawning threads to do Nasal stuff, but obviously contact with the rest of FlightGear must be hand-synchronized as FlightGear isn't threadsafe. The io library is no doubt the most useful, as it exposes all the basic stdio.h facilities; it's also frighteningly dangerous when combined with networked code...
This commit is contained in:
parent
37acfd4e25
commit
c30ff46f83
1 changed files with 17 additions and 21 deletions
|
@ -86,12 +86,7 @@ FGNasalSys::~FGNasalSys()
|
|||
for(it = _listener.begin(); it != end; ++it)
|
||||
delete it->second;
|
||||
|
||||
// Nasal doesn't have a "destroy context" API yet. :(
|
||||
// Not a problem for a global subsystem that will never be
|
||||
// destroyed. And the context is actually a global, so no memory
|
||||
// is technically leaked (although the GC pool memory obviously
|
||||
// won't be freed).
|
||||
_context = 0;
|
||||
naFreeContext(_context);
|
||||
_globals = naNil();
|
||||
}
|
||||
|
||||
|
@ -379,17 +374,15 @@ void FGNasalSys::init()
|
|||
// sub-reference under the name "globals". This gives client-code
|
||||
// write access to the namespace if someone wants to do something
|
||||
// fancy.
|
||||
_globals = naStdLib(_context);
|
||||
_globals = naInit_std(_context);
|
||||
naSave(_context, _globals);
|
||||
hashset(_globals, "globals", _globals);
|
||||
|
||||
// Add in the math library under "math"
|
||||
hashset(_globals, "math", naMathLib(_context));
|
||||
|
||||
// Add in the IO library. Disabled currently until after the
|
||||
// 0.9.10 release.
|
||||
// hashset(_globals, "io", naIOLib(_context));
|
||||
// hashset(_globals, "bits", naBitsLib(_context));
|
||||
hashset(_globals, "math", naInit_math(_context));
|
||||
hashset(_globals, "bits", naInit_bits(_context));
|
||||
hashset(_globals, "io", naInit_io(_context));
|
||||
hashset(_globals, "thread", naInit_thread(_context));
|
||||
hashset(_globals, "utf8", naInit_utf8(_context));
|
||||
|
||||
// Add our custom extension functions:
|
||||
for(i=0; funcs[i].name; i++)
|
||||
|
@ -585,21 +578,24 @@ bool FGNasalSys::handleCommand(const SGPropertyNode* arg)
|
|||
naRef code = parse(arg->getPath(true), nasal, strlen(nasal));
|
||||
if(naIsNil(code)) return false;
|
||||
|
||||
naContext c = naNewContext();
|
||||
// Commands can be run "in" a module. Make sure that module
|
||||
// exists, and set it up as the local variables hash for the
|
||||
// command.
|
||||
naRef locals = naNil();
|
||||
if(moduleName[0]) {
|
||||
naRef modname = naNewString(c);
|
||||
naRef modname = naNewString(_context);
|
||||
naStr_fromdata(modname, (char*)moduleName, strlen(moduleName));
|
||||
if(!naHash_get(_globals, modname, &locals))
|
||||
locals = naNewHash(c);
|
||||
hashset(_globals, moduleName, locals);
|
||||
if(!naHash_get(_globals, modname, &locals)) {
|
||||
locals = naNewHash(_context);
|
||||
naHash_set(_globals, modname, locals);
|
||||
}
|
||||
}
|
||||
// Cache the command argument for inspection via cmdarg(). For
|
||||
|
||||
// Cache this command's argument for inspection via cmdarg(). For
|
||||
// performance reasons, we won't bother with it if the invoked
|
||||
// code doesn't need it.
|
||||
_cmdArg = (SGPropertyNode*)arg;
|
||||
|
||||
// Call it!
|
||||
call(code, locals);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue