Register requires an object handle (instead of a SquirrelObject):
Register(SquirrelVM::GetVMPtr(), SysNamespace.GetObjectHandle(), WrapOutputDebug, "Debug");
Tested examples:
void globalFunc(const char * s,int val) {
printf("globalFunc: s: %s val: %d\n",s,val);
} // globalFunc
// You can add functions/vars here, as well as bind globals to be accessed through this class as shown in the Namespace example below.
// If the class is instantiated in script, the instance is "locked", preventing accidental changes to elements.
// Thus using an instance as the namespace can be a better design for development.
struct NameSpaceClass {
};
...
// Init and test:
HSQUIRRELVM v = SquirrelVM::GetVMPtr();
SquirrelObject root = SquirrelVM::GetRootTable();
// Create a namespace using a table.
SquirrelObject nameSpaceTable = SquirrelVM::CreateTable();
root.SetValue("Namespace1",nameSpaceTable);
Register(v,nameSpaceTable.GetObjectHandle(),globalFunc,"nameSpaceFunc");
// Create a namespace using a class. If an instance is created from this class, using the instance will prevent accidental changes to the instance members.
// Using the class/instance form also allows extra information to be added to the proxy class (and registered), if desired (such as vars/funcs).
SQClassDef("NameSpace2").
staticFunc(globalFunc,"nameSpaceFunc");
SquirrelObject testNameSpace = SquirrelVM::CompileBuffer("\
Namespace1.nameSpaceFunc(\"Hello Namespace1 (table),\",321); \n\
NameSpace2.nameSpaceFunc(\"Hello Namespace2 (class),\",654); \n\
local NameSpace3 = NameSpace2(); \n\
NameSpace3.nameSpaceFunc(\"Hello Namespace3 (instance),\",987); \n\
");
SquirrelVM::RunScript(testNameSpace);
John