- More work on scripting interface
[supertux.git] / tools / miniswig / main.cpp
index 94393df..2417198 100644 (file)
@@ -12,11 +12,12 @@ extern int yylex();
 CompilationUnit* unit = 0;
 std::istream* input = 0;
 std::string inputfile;
+std::string selected_namespace;
 std::string modulename = "wrapper";
 
 void usage()
 {
-    std::cout << "Usage: miniswig --input FILE --output-cpp FILE --output-hpp FILE [--module NAME]\n";
+    std::cout << "Usage: miniswig --input FILE --output-cpp FILE --output-hpp FILE [--module NAME] [--select-namespace NAME]\n";
     std::cout << "\n";
 }
 
@@ -53,6 +54,13 @@ int main(int argc, char** argv)
                 return 1;
             }
             outputhpp = argv[++i];
+        } else if(strcmp(argv[i], "--select-namespace") == 0) {
+            if(i+1 >= argc) {
+                std::cerr << "Need to specify a namespace.\n";
+                usage();
+                return 1;
+            }
+            selected_namespace = argv[++i];
         } else if(argv[i][0] == '-') {
             std::cerr << "Unknown option '" << argv[i] << "'.\n";
             usage();
@@ -73,11 +81,13 @@ int main(int argc, char** argv)
             return 1;
         }
         unit = new CompilationUnit();
-        unit->types.push_back(new StringType());
         Namespace* std_namespace = new Namespace();
         std_namespace->name = "std";
+        std_namespace->types.push_back(new StringType());
         unit->namespaces.push_back(std_namespace);
+        
         yyparse();
+
         std::ofstream cppout(outputcpp.c_str());
         if(!cppout.good()) {
             std::cerr << "Couldn't open file '" << outputcpp << "' for writing.\n";
@@ -88,8 +98,14 @@ int main(int argc, char** argv)
             std::cerr << "Couldn't open file '" << outputhpp << "' for writing.\n";
             return 1;
         }
+
+        Namespace* ns = unit;
+        if(selected_namespace != "") {
+            ns = ns->findNamespace(selected_namespace);
+        }
+
         WrapperCreator creator(cppout, hppout);
-        creator.create_wrapper(unit);
+        creator.create_wrapper(ns);
     } catch(std::exception& e) {
         std::cerr << e.what() << "\n";
         return 1;