summaryrefslogtreecommitdiff
path: root/src/script/squirrel_helper.hpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-12-19 21:00:32 +0000
committertruebrain <truebrain@openttd.org>2011-12-19 21:00:32 +0000
commit3a535690d4e9aaa896a062e7b5b5454b1b07ac47 (patch)
tree600859d25db8391542b9cc0da9e063c7bdc6f4fc /src/script/squirrel_helper.hpp
parent77b7366c2947a3f2545d5542021be1cc203a74e8 (diff)
downloadopenttd-3a535690d4e9aaa896a062e7b5b5454b1b07ac47.tar.xz
(svn r23623) -Add: allow bi-directional communication with the AdminPort and GameScript
Diffstat (limited to 'src/script/squirrel_helper.hpp')
-rw-r--r--src/script/squirrel_helper.hpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp
index cdc4b8b8f..a72199dce 100644
--- a/src/script/squirrel_helper.hpp
+++ b/src/script/squirrel_helper.hpp
@@ -831,6 +831,28 @@ namespace SQConvert {
}
}
+
+ /**
+ * A general template for all static advanced method callbacks from Squirrel.
+ * In here the function_proc is recovered, and the SQCall is called that
+ * can handle this exact amount of params.
+ */
+ template <typename Tcls, typename Tmethod>
+ inline SQInteger DefSQAdvancedStaticCallback(HSQUIRRELVM vm)
+ {
+ /* Find the amount of params we got */
+ int nparam = sq_gettop(vm);
+ SQUserPointer ptr = NULL;
+
+ /* Get the real function pointer */
+ sq_getuserdata(vm, nparam, &ptr, 0);
+ /* Remove the userdata from the stack */
+ sq_pop(vm, 1);
+
+ /* Call the function, which its only param is always the VM */
+ return (SQInteger)(*(*(Tmethod *)ptr))(vm);
+ }
+
/**
* A general template for the destructor of SQ instances. This is needed
* here as it has to be in the same scope as DefSQConstructorCallback.