miniswig suspend is now an attribute appended to functions
authorMatthias Braun <matze@braunis.de>
Sun, 10 Jul 2005 16:52:55 +0000 (16:52 +0000)
committerMatthias Braun <matze@braunis.de>
Sun, 10 Jul 2005 16:52:55 +0000 (16:52 +0000)
SVN-Revision: 2709

src/audio/sound_manager.cpp
src/scripting/functions.hpp
tools/miniswig/create_wrapper.cpp
tools/miniswig/lexer.ll
tools/miniswig/parser.yy
tools/miniswig/tree.hpp

index 9f21af2..963ce94 100644 (file)
@@ -267,7 +267,7 @@ SoundManager::print_openal_version()
   std::cout << "OpenAL Vendor: " << alGetString(AL_VENDOR) << "\n"
             << "OpenAL Version: " << alGetString(AL_VERSION) << "\n" 
             << "OpenAL Renderer: " << alGetString(AL_RENDERER) << "\n"
-            << "OpenAl Extensions: " << alGetString(AL_RENDERER) << "\n";
+            << "OpenAl Extensions: " << alGetString(AL_EXTENSIONS) << "\n";
 }
 
 void
index debc9af..512c69e 100644 (file)
@@ -1,22 +1,26 @@
 #ifndef __FUNCTIONS_H__
 #define __FUNCTIONS_H__
 
+#ifndef SCRIPTING_API
+#define __suspend
+#endif
+
 namespace Scripting
 {
 
 /** displays a text file and scrolls it over the screen */
 void display_text_file(const std::string& filename);
-/** @SUSPEND@ 
+/**
  * Suspends the script execution for the specified number of seconds
- * */
-void wait(float seconds);
+ */
+void wait(float seconds) __suspend;
 /** translates a give text into the users language (by looking it up in the .po
  * files)
  */
 std::string translate(const std::string& text);
 /** load a script file and executes it 
  * This is typically used to import functions from external files.
- * */
+ */
 void import(HSQUIRRELVM v, const std::string& filename);
 
 }
index 767e5c4..1fba6e7 100644 (file)
@@ -314,12 +314,16 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function)
     }
     out << ind << "\n";
     // push return value back on stack and return
-    if(function->return_type.is_void()) {
-        if(function->docu_comment.find("@SUSPEND@") != std::string::npos) {
-          out << ind << "return sq_suspendvm(v);\n";
-        } else {
-          out << ind << "return 0;\n";
+    if(function->suspend) {
+        if(!function->return_type.is_void()) {
+            std::stringstream msg;
+            msg << "Function '" << function->name << "' declared as suspend"
+                << " but has a return value.";
+            throw std::runtime_error(msg.str());
         }
+        out << ind << "return sq_suspendvm(v);\n";
+    } else if(function->return_type.is_void()) {
+        out << ind << "return 0;\n";
     } else {
         push_to_stack(function->return_type, "return_value");
         out << ind << "return 1;\n";
index ac699ab..263464d 100644 (file)
@@ -94,6 +94,7 @@ public                                  { return T_PUBLIC; }
 protected                               { return T_PROTECTED; }
 private                                 { return T_PRIVATE; }
 namespace                               { return T_NAMESPACE; }
+__suspend                               { return T_SUSPEND; }
 [a-zA-Z_][a-zA-Z_0-9]*                  {
         Namespace* ns = search_namespace;
         if(ns == 0)
index 8728b87..461c9f8 100644 (file)
@@ -69,6 +69,7 @@ private:
 %token T_CLASS
 %token T_STRUCT
 %token T_STATIC
+%token T_SUSPEND
 %token T_CONST
 %token T_UNSIGNED
 %token T_SIGNED
@@ -298,15 +299,19 @@ function_declaration:
             current_function->docu_comment = last_docucomment;
             last_docucomment = "";
         }                           
-    parameter_list ')' maybe_const abstract_declaration ';'
+    parameter_list ')' function_attributes abstract_declaration ';'
         {
             $$ = current_function;
         }
 ;
 
-maybe_const:
+function_attributes:
     /* empty */
-    | T_CONST
+    | T_CONST function_attributes
+    | T_SUSPEND function_attributes
+      {
+        current_function->suspend = true;
+      }
 ;
 
 abstract_declaration:
index 6e200da..0edca2e 100644 (file)
@@ -155,12 +155,18 @@ public:
 
 class Function : public ClassMember {
 public:
+    Function() {
+      type = FUNCTION;
+      suspend = false;
+    }
+  
     enum FuncType {
         FUNCTION,
         CONSTRUCTOR,
         DESTRUCTOR
     };
     FuncType type;
+    bool suspend;
     std::string docu_comment;
     std::string name;
     Type return_type;