summaryrefslogtreecommitdiff
path: root/src/scripting/script.h
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-28 23:37:23 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-02 18:12:20 +0100
commitba5b55f3eba0aa3898c5fe42de9838b22473c24a (patch)
tree465e70d3bc4671b75f1af763d866eafa459f5d6f /src/scripting/script.h
parent05bb880a3b0ebe401bac83b7a2400aa315161f9c (diff)
downloadmanaserv-ba5b55f3eba0aa3898c5fe42de9838b22473c24a.tar.gz
manaserv-ba5b55f3eba0aa3898c5fe42de9838b22473c24a.tar.bz2
manaserv-ba5b55f3eba0aa3898c5fe42de9838b22473c24a.tar.xz
manaserv-ba5b55f3eba0aa3898c5fe42de9838b22473c24a.zip
Use callbacks for handling character death and respawn
Rather than relying on the availability of global functions with certain predefined names, the Lua script now calls API functions to set which function should be called on these global events. This mechanism should make it easier to avoid name collisions in the global namespace, which is important now that there is only a single script state. For these global events this was not likely to become a problem, but this solution can also be used for callbacks on specific item or monster types, or even allow setting callbacks on certain instances. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/scripting/script.h')
-rw-r--r--src/scripting/script.h33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/scripting/script.h b/src/scripting/script.h
index bd143114..b475a0f0 100644
--- a/src/scripting/script.h
+++ b/src/scripting/script.h
@@ -21,11 +21,12 @@
#ifndef SCRIPTING_SCRIPT_H
#define SCRIPTING_SCRIPT_H
-#include <string>
-
-#include "game-server/character.h"
+#include "common/inventorydata.h"
#include "game-server/eventlistener.h"
+#include <list>
+#include <string>
+
class MapComposite;
class Thing;
@@ -35,7 +36,9 @@ class Thing;
class Script
{
public:
-
+ /**
+ * Defines a function that creates a Script instance.
+ */
typedef Script *(*Factory)();
/**
@@ -48,6 +51,15 @@ class Script
*/
static Script *create(const std::string &engine);
+ /**
+ * A reference to a script object. It's just an integer, but the
+ * typedef makes the purpose of the variable clear.
+ *
+ * Variables of this type should be initialized to Script::NoRef.
+ */
+ typedef int Ref;
+ static Ref NoRef;
+
Script();
virtual ~Script() {}
@@ -81,6 +93,12 @@ class Script
virtual void update();
/**
+ * Prepares a call to the referenced function.
+ * Only one function can be prepared at once.
+ */
+ virtual void prepare(Ref function) = 0;
+
+ /**
* Prepares a call to the given function.
* Only one function can be prepared at once.
*/
@@ -117,6 +135,13 @@ class Script
virtual int execute() = 0;
/**
+ * Assigns the current callback to the given \a function.
+ *
+ * Where the callback exactly comes from is up to the script engine.
+ */
+ virtual void assignCallback(Ref &function) = 0;
+
+ /**
* Sets associated map.
*/
void setMap(MapComposite *m)