summaryrefslogtreecommitdiff
path: root/src/script/squirrel_helper.hpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2011-12-21 14:55:28 +0000
committeryexo <yexo@openttd.org>2011-12-21 14:55:28 +0000
commit5988659eea20d3e84fdeadf448133e9b94e9630f (patch)
tree230c16eadf35e9868a3acf6d91b1b73ae412897d /src/script/squirrel_helper.hpp
parenta55478aaa6453d62f9708ee03393711b2d3120ee (diff)
downloadopenttd-5988659eea20d3e84fdeadf448133e9b94e9630f.tar.xz
(svn r23651) -Feature: [NoGo] GSText now accepts string arguments as parameters to the constructor
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 a72199dce..6314d3bc2 100644
--- a/src/script/squirrel_helper.hpp
+++ b/src/script/squirrel_helper.hpp
@@ -885,6 +885,28 @@ namespace SQConvert {
}
}
+ /**
+ * A general template to handle creating of an instance with a complex
+ * constructor.
+ */
+ template <typename Tcls>
+ inline SQInteger DefSQAdvancedConstructorCallback(HSQUIRRELVM vm)
+ {
+ try {
+ /* Find the amount of params we got */
+ int nparam = sq_gettop(vm);
+
+ /* Create the real instance */
+ Tcls *instance = new Tcls(vm);
+ sq_setinstanceup(vm, -nparam, instance);
+ sq_setreleasehook(vm, -nparam, DefSQDestructorCallback<Tcls>);
+ instance->AddRef();
+ return 0;
+ } catch (SQInteger e) {
+ return e;
+ }
+ }
+
} // namespace SQConvert
#endif /* SQUIRREL_HELPER_HPP */