allow custom wrapper functions
authorMatthias Braun <matze@braunis.de>
Tue, 12 Jul 2005 22:39:45 +0000 (22:39 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 12 Jul 2005 22:39:45 +0000 (22:39 +0000)
SVN-Revision: 2718

tools/miniswig/create_wrapper.cpp
tools/miniswig/lexer.ll
tools/miniswig/main.cpp
tools/miniswig/parser.yy
tools/miniswig/tree.hpp

index 1fba6e7..7e44cd6 100644 (file)
@@ -263,6 +263,28 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function)
         out << ind << ns_prefix <<  _class->name << "* _this;\n";
         out << ind << "sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0);\n";
     }
+
+    // custom function?
+    if(function->custom) {
+        if(function->type != Function::FUNCTION)
+            throw std::runtime_error(
+                    "custom not allow constructor+destructor yet");
+        if(function->return_type.atomic_type != &BasicType::INT)
+            throw std::runtime_error("custom function has to return int");
+        if(function->parameters.size() != 1)
+            throw std::runtime_error(
+                    "custom function must have 1 HSQUIRRELVM parameter");
+
+        out << ind << "return ";
+        if(_class != 0)
+            out << "_this->";
+        else
+            out << ns_prefix;
+        out << function->name << "(v);\n";
+        out << "}\n";
+        out << "\n";
+        return;
+    }
     
     // declare and retrieve arguments
     int i = 0;
@@ -431,7 +453,8 @@ WrapperCreator::create_squirrel_instance(Class* _class)
         << ind << ind << "sq_setreleasehook(v, -1, "
         << _class->name << "_release_hook);\n"
         << ind << "}\n"
-        << "}\n";
+        << "}\n"
+        << "\n";
 }
 
 void
index 263464d..e22fac1 100644 (file)
@@ -95,6 +95,7 @@ protected                               { return T_PROTECTED; }
 private                                 { return T_PRIVATE; }
 namespace                               { return T_NAMESPACE; }
 __suspend                               { return T_SUSPEND; }
+__custom                                { return T_CUSTOM; }
 [a-zA-Z_][a-zA-Z_0-9]*                  {
         Namespace* ns = search_namespace;
         if(ns == 0)
index 2655a64..cbb76f1 100644 (file)
@@ -97,7 +97,7 @@ int main(int argc, char** argv)
         std_namespace->types.push_back(new StringType());
         unit->namespaces.push_back(std_namespace);
         unit->types.push_back(new HSQUIRRELVMType());
-        
+       
         yyparse();
 
         Namespace* ns = unit;
@@ -127,14 +127,14 @@ int main(int argc, char** argv)
             std::ofstream dout(output_doc.c_str());
             if(!dout.good()) {
                 std::cerr << "Couldn't open file '" 
-                    << dout << "' for writing.\n";
+                    << output_doc << "' for writing.\n";
                 return 1;
             }
             DocuCreator creator(dout);
             creator.create_docu(ns);
         }
     } catch(std::exception& e) {
-        std::cerr << e.what() << "\n";
+        std::cerr << "Exception: " << e.what() << "\n";
         return 1;
     }
 
index 461c9f8..a54c0af 100644 (file)
@@ -70,6 +70,7 @@ private:
 %token T_STRUCT
 %token T_STATIC
 %token T_SUSPEND
+%token T_CUSTOM
 %token T_CONST
 %token T_UNSIGNED
 %token T_SIGNED
@@ -308,6 +309,10 @@ function_declaration:
 function_attributes:
     /* empty */
     | T_CONST function_attributes
+    | T_CUSTOM function_attributes
+      {
+        current_function->custom = true;
+      }
     | T_SUSPEND function_attributes
       {
         current_function->suspend = true;
index 0edca2e..4dfcf1b 100644 (file)
@@ -158,6 +158,7 @@ public:
     Function() {
       type = FUNCTION;
       suspend = false;
+      custom = false;
     }
   
     enum FuncType {
@@ -166,7 +167,10 @@ public:
         DESTRUCTOR
     };
     FuncType type;
+    /// function should suspend squirrel VM after execution
     bool suspend;
+    /// a custom wrapper (just pass along HSQUIRRELVM)
+    bool custom;
     std::string docu_comment;
     std::string name;
     Type return_type;