20,741
edits
| Line 103: | Line 103: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= Allocating Nasal types = | |||
Nasal types (scalars, vectors, hashes, funcs, ghosts) are allocated via wrappers in [https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c misc.c]. | |||
These wrappers are: | |||
* naNewString(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line77 | |||
* naNewVector(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line87 | |||
* naNewHash(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line94 | |||
* naNewCode(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line101 | |||
* naNewCCode(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line106 | |||
* naNewFunc(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line113 | |||
* naNewGhost(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line122 | |||
* naNewGhost2(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line135 | |||
All of these wrappers are really just helpers on top of naNew(), they just set up type-specific information and initialize each Nasal type properly. | |||
For instance, first naNew() is called for the given context, along with the type info (to set up the size properly)- and then each type is initialized: | |||
<syntaxhighlight lang="C"> | |||
naRef naNewString(struct Context* c) | |||
{ | |||
naRef s = naNew(c, T_STR); | |||
PTR(s).str->emblen = 0; | |||
PTR(s).str->data.ref.len = 0; | |||
PTR(s).str->data.ref.ptr = 0; | |||
PTR(s).str->hashcode = 0; | |||
return s; | |||
} | |||
</syntaxhighlight> | |||
== The pool manager == | == The pool manager == | ||