summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-08-20 10:48:20 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-08-20 10:48:20 +0000
commit2e131bd3cbb2acb6ef52e7ad85f354ede543a392 (patch)
tree273b131f076989d6e7bf2f9b6b2a1cf07fcceba9
parentdde3886a5067d1b49ac8ad50383c388f469978b3 (diff)
downloadmanaserv-2e131bd3cbb2acb6ef52e7ad85f354ede543a392.tar.gz
manaserv-2e131bd3cbb2acb6ef52e7ad85f354ede543a392.tar.bz2
manaserv-2e131bd3cbb2acb6ef52e7ad85f354ede543a392.tar.xz
manaserv-2e131bd3cbb2acb6ef52e7ad85f354ede543a392.zip
Defined two helper functions to abstract away money being available under
inventory index 0.
-rw-r--r--ChangeLog5
-rw-r--r--data/scripts/libtmw.lua10
-rw-r--r--data/test.lua10
-rw-r--r--src/scripting/lua.cpp10
-rw-r--r--src/scripting/script.hpp8
5 files changed, 37 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 8e6b0a7b..499cd138 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-08-20 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * data/test.lua, data/scripts/libtmw.lua: Defined two helper functions
+ to abstract away money being available under inventory index 0.
+
2007-08-20 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/scripting/script.cpp: Prevented access to uninitialized engines.
diff --git a/data/scripts/libtmw.lua b/data/scripts/libtmw.lua
index 158befe3..5fc894e8 100644
--- a/data/scripts/libtmw.lua
+++ b/data/scripts/libtmw.lua
@@ -160,3 +160,13 @@ function initialize()
end
init_fun = nil
end
+
+-- Below are some convenience methods added to the engine API
+
+tmw.chr_money_change = function(ch, amount)
+ return tmw.chr_inv_change(ch, 0, amount)
+end
+
+tmw.chr_money = function(ch)
+ return tmw.chr_inv_count(ch, 0)
+end
diff --git a/data/test.lua b/data/test.lua
index 817c5ce0..6254225a 100644
--- a/data/test.lua
+++ b/data/test.lua
@@ -11,7 +11,11 @@ function my_npc1(npc, ch)
do_message(npc, ch, "Hello! I am the testing NPC.")
do_message(npc, ch, "This message is just here for testing intertwined connections.")
do_message(npc, ch, "What do you want?")
- local v = do_choice(npc, ch, "Guns! Lots of guns!", "A Christmas party!", "To buy.", "To sell.", "To make a donation.")
+ local v = do_choice(npc, ch, "Guns! Lots of guns!",
+ "A Christmas party!",
+ "To buy.",
+ "To sell.",
+ "To make a donation.")
if v == 1 then
do_message(npc, ch, "Sorry, this is a heroic-fantasy game, I do not have any gun.")
elseif v == 2 then
@@ -30,8 +34,8 @@ function my_npc1(npc, ch)
elseif v == 4 then
tmw.npc_trade(npc, ch, true, { {511, 10, 200}, {524, 10, 300}, {508, 10, 500}, {537, 10, 25} })
elseif v == 5 then
- if tmw.chr_inv_change(ch, 0, -100) then
- do_message(npc, ch, string.format("Thank you for you patronage! You are left with %d gil.", tmw.chr_inv_count(ch, 0)))
+ if tmw.chr_money_change(ch, -100) then
+ do_message(npc, ch, string.format("Thank you for you patronage! You are left with %d gil.", tmw.chr_money(ch)))
else
do_message(npc, ch, "I would feel bad taking money from someone that poor.")
end
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 8c872c49..6e30dbe0 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -48,9 +48,14 @@ extern "C" {
class LuaScript: public Script
{
public:
-
+ /**
+ * Constructor.
+ */
LuaScript();
+ /**
+ * Destructor.
+ */
~LuaScript();
void load(char const *);
@@ -440,7 +445,8 @@ void LuaScript::load(char const *prog)
return;
}
- // A Lua chunk is like a function, so "execute" it in order to initialize it.
+ // A Lua chunk is like a function, so "execute" it in order to initialize
+ // it.
res = lua_pcall(mState, 0, 0, 0);
if (res)
{
diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp
index 65fc0044..963c51f2 100644
--- a/src/scripting/script.hpp
+++ b/src/scripting/script.hpp
@@ -48,8 +48,14 @@ class Script
*/
static Script *create(std::string const &engine);
+ /**
+ * Constructor.
+ */
Script(): mMap(NULL) {}
+ /**
+ * Destructor.
+ */
virtual ~Script() {}
/**
@@ -91,7 +97,7 @@ class Script
* Pushes a pointer argument to a game entity.
* The interface can pass the pointer as an opaque value to the
* scripting engine, if needed. This value will usually be passed
- * by the script to some callabck functions.
+ * by the script to some callback functions.
*/
virtual void push(Thing *) = 0;