projects
/
supertux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4eff38d
)
Added type checking for __custom functions
author
Ingo Ruhnke
<grumbel@gmx.de>
Mon, 16 Mar 2009 18:10:50 +0000
(18:10 +0000)
committer
Ingo Ruhnke
<grumbel@gmx.de>
Mon, 16 Mar 2009 18:10:50 +0000
(18:10 +0000)
SVN-Revision: 5864
src/scripting/functions.hpp
patch
|
blob
|
history
tools/miniswig/create_wrapper.cpp
patch
|
blob
|
history
tools/miniswig/parser.yy
patch
|
blob
|
history
tools/miniswig/tree.hpp
patch
|
blob
|
history
diff --git
a/src/scripting/functions.hpp
b/src/scripting/functions.hpp
index
a219aef
..
3cff6f9
100644
(file)
--- a/
src/scripting/functions.hpp
+++ b/
src/scripting/functions.hpp
@@
-22,7
+22,7
@@
#ifndef SCRIPTING_API
#define __suspend
#ifndef SCRIPTING_API
#define __suspend
-#define __custom
+#define __custom
(x)
#include <string>
#endif
#include <string>
#endif
@@
-32,7
+32,7
@@
namespace Scripting
/**
* Display the value of the argument. This is useful for inspecting tables.
*/
/**
* Display the value of the argument. This is useful for inspecting tables.
*/
-SQInteger display(HSQUIRRELVM vm) __custom;
+SQInteger display(HSQUIRRELVM vm) __custom
("t.")
;
/**
* Displays contents of the current stack
/**
* Displays contents of the current stack
@@
-42,7
+42,7
@@
void print_stacktrace(HSQUIRRELVM vm);
/**
* returns the currently running thread
*/
/**
* returns the currently running thread
*/
-SQInteger get_current_thread(HSQUIRRELVM vm) __custom;
+SQInteger get_current_thread(HSQUIRRELVM vm) __custom
("t")
;
/**
* Display a text file and scrolls it over the screen (on next screenswitch)
/**
* Display a text file and scrolls it over the screen (on next screenswitch)
diff --git
a/tools/miniswig/create_wrapper.cpp
b/tools/miniswig/create_wrapper.cpp
index
29f35b2
..
ba5a43f
100644
(file)
--- a/
tools/miniswig/create_wrapper.cpp
+++ b/
tools/miniswig/create_wrapper.cpp
@@
-122,10
+122,12
@@
WrapperCreator::create_register_function_code(Function* function, Class* _class)
<< (_class != 0 ? _class->name + "_" : "") << function->name
<< "_wrapper, 0);\n";
<< (_class != 0 ? _class->name + "_" : "") << function->name
<< "_wrapper, 0);\n";
- if(!function->custom) {
+ if(function->custom) {
+ out << ind << "sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, " << function->parameter_spec << ");\n";
+ } else {
out << ind << "sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, \"";
out << ind << "sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, \"";
- out << "x|t
";
+ out << "x|t";
if(!function->parameters.empty())
{
if(!function->parameters.empty())
{
@@
-133,20
+135,23
@@
WrapperCreator::create_register_function_code(Function* function, Class* _class)
// Skip the first parameter since its a HSQUIRRELVM that is
// handled internally
// Skip the first parameter since its a HSQUIRRELVM that is
// handled internally
- if (function->suspend)
+ if (function->suspend)
{
++p;
++p;
-
+ } else if (p->type.atomic_type == HSQUIRRELVMType::instance()) {
+ ++p;
+ }
+
for(; p != function->parameters.end(); ++p) {
if(p->type.atomic_type == &BasicType::INT) {
for(; p != function->parameters.end(); ++p) {
if(p->type.atomic_type == &BasicType::INT) {
- out << "i
";
+ out << "i";
} else if(p->type.atomic_type == &BasicType::FLOAT) {
} else if(p->type.atomic_type == &BasicType::FLOAT) {
- out << "
f|i
";
+ out << "
n
";
} else if(p->type.atomic_type == &BasicType::BOOL) {
} else if(p->type.atomic_type == &BasicType::BOOL) {
- out << "b
";
+ out << "b";
} else if(p->type.atomic_type == StringType::instance()) {
} else if(p->type.atomic_type == StringType::instance()) {
- out << "s
";
+ out << "s";
} else {
} else {
- out << ".
";
+ out << ".";
}
}
}
}
}
}
@@
-313,14
+318,14
@@
WrapperCreator::create_function_wrapper(Class* _class, Function* function)
// custom function?
if(function->custom) {
// custom function?
if(function->custom) {
- if(function->type != Function::FUNCTION)
+ if(function->type != Function::FUNCTION)
throw std::runtime_error(
"custom not allow constructor+destructor yet");
if(function->return_type.atomic_type != SQIntegerType::instance())
throw std::runtime_error(
"custom not allow constructor+destructor yet");
if(function->return_type.atomic_type != SQIntegerType::instance())
- throw std::runtime_error("custom function has to return SQInteger");
+ throw std::runtime_error("custom function
'" + function->name + "'
has to return SQInteger");
if(function->parameters.size() != 1)
throw std::runtime_error(
if(function->parameters.size() != 1)
throw std::runtime_error(
- "custom function must have 1 HSQUIRRELVM parameter");
+ "custom function
'" + function->name + "'
must have 1 HSQUIRRELVM parameter");
out << ind << "return ";
if(_class != 0)
out << ind << "return ";
if(_class != 0)
diff --git
a/tools/miniswig/parser.yy
b/tools/miniswig/parser.yy
index
2d6000f
..
03fb00c
100644
(file)
--- a/
tools/miniswig/parser.yy
+++ b/
tools/miniswig/parser.yy
@@
-308,8
+308,9
@@
function_declaration:
function_attributes:
/* empty */
| T_CONST function_attributes
function_attributes:
/* empty */
| T_CONST function_attributes
- | T_CUSTOM function_attributes
+ | T_CUSTOM
'(' T_STRING ')'
function_attributes
{
{
+ current_function->parameter_spec = $3;
current_function->custom = true;
}
| T_SUSPEND function_attributes
current_function->custom = true;
}
| T_SUSPEND function_attributes
diff --git
a/tools/miniswig/tree.hpp
b/tools/miniswig/tree.hpp
index
b6c87fa
..
5c7927f
100644
(file)
--- a/
tools/miniswig/tree.hpp
+++ b/
tools/miniswig/tree.hpp
@@
-193,6
+193,7
@@
public:
bool suspend;
/// a custom wrapper (just pass along HSQUIRRELVM)
bool custom;
bool suspend;
/// a custom wrapper (just pass along HSQUIRRELVM)
bool custom;
+ std::string parameter_spec;
std::string docu_comment;
std::string name;
Type return_type;
std::string docu_comment;
std::string name;
Type return_type;