newspeoplefor developersdocumentationdownloads

Object System
[Nebula Kernel]


Detailed Description

Nebula provides an object system to provide metadata for the scripting system. This is a key part that allows Nebula to support object persistence and multiple scripting languages with relative ease.

Named Object Hierarchy

An instance of a class that is derived from nRoot is called a Nebula Object. Nebula objects have a unique name that can be converted to a C++ pointer and back. This feature is very useful for scripting and object persistency.

Nebula objects are arranged in a hierarchy similiar to a filesystem. This is often referred to as the "Named Object Hierarchy". or NOH. The path to any particular named object is unique and is used as that object's unique name. The tree of named objects can be navigated with the built-in command console (see Console Server). Within C++ named objects are accessible through references (see Smart Pointers).

Creation

To use Nebula scripting interface, the class instance which you want to create should be derived from nRoot class. All nRoot derived classes should be created by nKernelServer::New with given class name and object name. The class name is the name given to the module that contains the class, this is set in your .bld files.

Here's an example:

    nShapeNode* node = nKernelServer::Instance()->New("nshapenode", "/usr/scene/node1");

As mentioned above, Nebula object uses class name and object name for it's creation. 'nshapenode' is the class name and '/usr/scene/node1' is the object name in the code example.

Persistence

A Nebula object can be serialized. You can save an object from the Nebula console. (Assume that you use ntclserver for script server)
    > sel /usr/scene
    > <objectname>.save

Note:
You should reimplement nRoot::SaveCmds() to use object serialization. See Writing A New nRoot Derived Class more details.
The <objectname> is whatever the name of the node which you want to save.

You can change the script server that is used to save objects by:

    > /sys/servers/persist.setsaverclass <script server class>

It is possible to have more than one script server if you want to. A .n2 file will only have nebula commands in it(sel, and any valid node commands). Those commands can all be saved and loaded by any script server. So you can use tcl script server on runtime and use python script server when you save an object if you want.

If you want to produce binary script from nebula object script try this:

    > /sys/serers/persist.setsaverclass nbinsriptserver

Note:
Using binary script server dramaticaly reduces loading time when it reads script file.


Classes

class  nClass
class  nCmd
class  nCmdProto
class  nCmdProtoNative
 A factory for nCmd objects that correspond to natively implemented script commands. More...

Defines

#define nNebulaUsePackage(PACKAGE)   extern "C" void PACKAGE()
#define nNebulaClass(CLASS, SUPERCLASSNAME)
#define nNebulaClassStaticInit(CLASS, SUPERCLASSNAME, INITSTATICDATAFUNC)
#define nNebulaScriptClass(CLASS, SUPERCLASSNAME)
#define nNebulaScriptClassStaticInit(CLASS, SUPERCLASSNAME, INITSTATICDATAFUNC)
#define nNebulaRootClass(CLASS)

Define Documentation

#define nNebulaUsePackage PACKAGE   )     extern "C" void PACKAGE()
 

Wraps the Nebula class package initialization function.

Use like this:

    nNebulaUsePackage(blub);

    void bla()
    {
        nKernelServer kernelServer;
        kernelServer.AddPackage(blub);
    }

Definition at line 32 of file ndefclass.h.

#define nNebulaClass CLASS,
SUPERCLASSNAME   ) 
 

Value:

extern bool n_init(nClass* clazz, nKernelServer* kernelServer); \
    extern void* n_create(); \
    bool n_init(nClass* clazz, nKernelServer* kernelServer) {\
        clazz->SetProperName(#CLASS); \
        clazz->SetInstanceSize(sizeof(CLASS)); \
        kernelServer->AddClass(SUPERCLASSNAME, clazz); \
        return true; \
    } \
    void* n_create() { return n_new(CLASS()); }
nNebulaClass() creates a simple Nebula class without script interface. It takes the C name of the class, and a string defining the superclass name:

    nNebulaClass(nTestClass, "nparentclass");

Definition at line 46 of file ndefclass.h.

#define nNebulaClassStaticInit CLASS,
SUPERCLASSNAME,
INITSTATICDATAFUNC   ) 
 

Value:

extern bool n_init(nClass* clazz, nKernelServer* kernelServer); \
    extern void* n_create(); \
    bool n_init(nClass* clazz, nKernelServer* kernelServer) {\
        clazz->SetProperName(#CLASS); \
        clazz->SetInstanceSize(sizeof(CLASS)); \
        kernelServer->AddClass(SUPERCLASSNAME, clazz); \
        INITSTATICDATAFUNC(); \
        return true; \
    } \
    void* n_create() { return n_new(CLASS()); }
nNebulaClassStaticInit(), declare Nebula class and call static data initialization function

    nNebulaClassStaticInit(nTestClass, "nparentclass", staticInitFunction);

Definition at line 68 of file ndefclass.h.

#define nNebulaScriptClass CLASS,
SUPERCLASSNAME   ) 
 

Value:

extern bool n_init(nClass* clazz, nKernelServer* kernelServer); \
    extern void* n_create(); \
    extern void n_initcmds(nClass*); \
    bool n_init(nClass* clazz, nKernelServer* kernelServer) {\
        clazz->SetProperName(#CLASS); \
        clazz->SetInstanceSize(sizeof(CLASS)); \
        kernelServer->AddClass(SUPERCLASSNAME, clazz); \
        n_initcmds(clazz); \
        return true; \
    } \
    void* n_create() { return n_new(CLASS()); }
nNebulaScriptClass() creates a Nebula class with script interface (you'll have to provide a function void n_initcmds(nClass*)). It takes the C name of the class, and a string defining the superclass name:

    nNebulaScriptClass(nTestClass, "nparentclass");

Definition at line 94 of file ndefclass.h.

#define nNebulaScriptClassStaticInit CLASS,
SUPERCLASSNAME,
INITSTATICDATAFUNC   ) 
 

Value:

extern bool n_init(nClass* clazz, nKernelServer* kernelServer); \
    extern void* n_create(); \
    extern void n_initcmds(nClass*); \
    bool n_init(nClass* clazz, nKernelServer* kernelServer) {\
        clazz->SetProperName(#CLASS); \
        clazz->SetInstanceSize(sizeof(CLASS)); \
        kernelServer->AddClass(SUPERCLASSNAME, clazz); \
        INITSTATICDATAFUNC(); \
        n_initcmds(clazz); \
        return true; \
    } \
    void* n_create() { return n_new(CLASS()); }
nNebulaScriptClassStaticInit(), declare Nebula class with script interface and call static data initialization function.

    nNebulaScriptClassStaticInit(nTestClass, "nparentclass", staticInitFunction);

Definition at line 118 of file ndefclass.h.

#define nNebulaRootClass CLASS   ) 
 

Value:

nKernelServer* CLASS::kernelServer = 0; \
    extern bool n_init(nClass* clazz, nKernelServer* kernelServer); \
    extern void* n_create(); \
    extern void n_initcmds(nClass*); \
    bool n_init(nClass* clazz, nKernelServer* kernelServer) {\
        CLASS::kernelServer = kernelServer; \
        clazz->SetProperName(#CLASS); \
        clazz->SetInstanceSize(sizeof(CLASS)); \
        n_initcmds(clazz); \
        return true; \
    } \
    void* n_create() { return n_new(CLASS()); }
    nNebulaRootClass(): Special macro for the Nebula root class

Definition at line 141 of file ndefclass.h.

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.