From: Matthias Braun Date: Sun, 10 Jul 2005 16:52:55 +0000 (+0000) Subject: miniswig suspend is now an attribute appended to functions X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8f82a8e619346be81a3c1bf943baf68953f1f4e7;p=supertux.git miniswig suspend is now an attribute appended to functions SVN-Revision: 2709 --- diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index 9f21af2b4..963ce94df 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -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 diff --git a/src/scripting/functions.hpp b/src/scripting/functions.hpp index debc9af70..512c69ee6 100644 --- a/src/scripting/functions.hpp +++ b/src/scripting/functions.hpp @@ -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); } diff --git a/tools/miniswig/create_wrapper.cpp b/tools/miniswig/create_wrapper.cpp index 767e5c48a..1fba6e7bc 100644 --- a/tools/miniswig/create_wrapper.cpp +++ b/tools/miniswig/create_wrapper.cpp @@ -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"; diff --git a/tools/miniswig/lexer.ll b/tools/miniswig/lexer.ll index ac699ab5b..263464de0 100644 --- a/tools/miniswig/lexer.ll +++ b/tools/miniswig/lexer.ll @@ -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) diff --git a/tools/miniswig/parser.yy b/tools/miniswig/parser.yy index 8728b87ad..461c9f80a 100644 --- a/tools/miniswig/parser.yy +++ b/tools/miniswig/parser.yy @@ -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: diff --git a/tools/miniswig/tree.hpp b/tools/miniswig/tree.hpp index 6e200dac5..0edca2ef3 100644 --- a/tools/miniswig/tree.hpp +++ b/tools/miniswig/tree.hpp @@ -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;