+void *SpiderScript_int_GetNamespace(tSpiderScript *Script, tSpiderNamespace *RootNamespace,
+ const char *BasePath, const char *ItemPath,
+ const char **ItemName
+ )
+{
+ int len;
+ const char *name;
+ const char *end;
+ int bTriedBase;
+
+ tSpiderNamespace *lastns, *ns;
+
+ // Prepend the base namespace
+ if( BasePath ) {
+ name = BasePath;
+ bTriedBase = 0;
+ }
+ else {
+ bTriedBase = 1;
+ name = ItemPath;
+ }
+
+ // Scan
+ lastns = RootNamespace;
+ do {
+ end = strchr(name, BC_NS_SEPARATOR);
+ if(!end) {
+ if( !bTriedBase )
+ len = strlen(name);
+ else
+ break;
+ }
+ else {
+ len = end - name;
+ }
+
+ // Check for this level
+ for( ns = lastns->FirstChild; ns; ns = ns->Next )
+ {
+ if( strncmp(name, ns->Name, len) == 0 && ns->Name[len] == 0 )
+ break ;
+ }
+
+ if(!ns) return NULL;
+
+ if(!end && !bTriedBase) {
+ end = ItemPath - 1; // -1 to counter (name = end + 1)
+ bTriedBase = 1;
+ }
+
+ lastns = ns;
+ name = end + 1;
+ } while( end );
+
+ *ItemName = name;
+
+ return lastns;
+}
+
+tSpiderFunction *SpiderScript_int_GetNativeFunction(tSpiderScript *Script, tSpiderNamespace *RootNamespace,
+ const char *BasePath, const char *FunctionPath)
+{
+ tSpiderNamespace *ns;
+ const char *name;
+ tSpiderFunction *fcn;
+
+ ns = SpiderScript_int_GetNamespace(Script, RootNamespace, BasePath, FunctionPath, &name);
+ if(!ns) return NULL;
+
+ for( fcn = ns->Functions; fcn; fcn = fcn->Next )
+ {
+ if( strcmp(name, fcn->Name) == 0 )
+ return fcn;
+ }
+
+ return NULL;
+}
+
+tSpiderObjectDef *SpiderScript_int_GetNativeClass(tSpiderScript *Script, tSpiderNamespace *RootNamespace,
+ const char *BasePath, const char *ClassPath
+ )
+{
+ tSpiderNamespace *ns;
+ const char *name;
+ tSpiderObjectDef *class;
+
+ ns = SpiderScript_int_GetNamespace(Script, RootNamespace, BasePath, ClassPath, &name);
+ if(!ns) return NULL;
+
+ for( class = ns->Classes; class; class = class->Next )
+ {
+ if( strcmp(name, class->Name) == 0 )
+ return class;
+ }
+
+ return NULL;
+}
+