summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-08-25 03:31:01 +0200
committerPhilipp Sehmisch <crush@themanaworld.org>2009-08-25 03:31:01 +0200
commit0e854932c635ac77103ffda6ad967f6ec172b0e8 (patch)
tree0d18cedc8b6faf3a1ca46a70677b1df7b9448ce5 /src
parent936c2d31127871e86918cf4e735da75186582543 (diff)
downloadmanaserv-0e854932c635ac77103ffda6ad967f6ec172b0e8.tar.gz
manaserv-0e854932c635ac77103ffda6ad967f6ec172b0e8.tar.bz2
manaserv-0e854932c635ac77103ffda6ad967f6ec172b0e8.tar.xz
manaserv-0e854932c635ac77103ffda6ad967f6ec172b0e8.zip
Made the STL container -> LUA table wrappers more flexible.
Diffstat (limited to 'src')
-rw-r--r--src/scripting/lua.cpp41
-rw-r--r--src/scripting/luautil.hpp6
2 files changed, 28 insertions, 19 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 7361cea0..f82b581a 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -487,7 +487,7 @@ static int npc_trade(lua_State *s)
*/
static int being_apply_status(lua_State *s)
-{
+{
if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2) || !lua_isnumber(s, 3))
{
raiseScriptError(s, "being_apply_status called with incorrect parameters.");
@@ -1204,35 +1204,44 @@ static int test_tableget(lua_State *s)
{
std::list<float> list;
- std::vector<std::string> vector;
+ std::vector<std::string> svector;
+ std::vector<int> ivector;
std::map<std::string, std::string> map;
std::set<int> set;
- LOG_INFO("Pushing List");
+ LOG_INFO("Pushing Float List");
list.push_back(12.636);
list.push_back(0.0000000045656);
list.push_back(185645445634566.346);
list.push_back(7835458.11);
pushSTLContainer<float>(s, list);
- LOG_INFO("Pushing Vector");
- vector.push_back("All");
- vector.push_back("your");
- vector.push_back("base");
- vector.push_back("are");
- vector.push_back("belong");
- vector.push_back("to");
- vector.push_back("us!");
- pushSTLContainer<std::string>(s, vector);
-
- LOG_INFO("Pushing Map");
+ LOG_INFO("Pushing String Vector");
+ svector.push_back("All");
+ svector.push_back("your");
+ svector.push_back("base");
+ svector.push_back("are");
+ svector.push_back("belong");
+ svector.push_back("to");
+ svector.push_back("us!");
+ pushSTLContainer<std::string>(s, svector);
+
+ LOG_INFO("Pushing Integer Vector");
+ ivector.resize(10);
+ for (int i = 1; i < 10; i++)
+ {
+ ivector[i-1] = i * i;
+ }
+ pushSTLContainer<int>(s, ivector);
+
+ LOG_INFO("Pushing String/String Map");
map["Apple"] = "red";
map["Banana"] = "yellow";
map["Lime"] = "green";
map["Plum"] = "blue";
pushSTLContainer<std::string, std::string>(s, map);
- LOG_INFO("Pushing Set");
+ LOG_INFO("Pushing Integer Set");
set.insert(12);
set.insert(8);
set.insert(14);
@@ -1240,7 +1249,7 @@ static int test_tableget(lua_State *s)
pushSTLContainer<int>(s, set);
- return 4;
+ return 5;
}
/**
diff --git a/src/scripting/luautil.hpp b/src/scripting/luautil.hpp
index 79623ab9..900f243f 100644
--- a/src/scripting/luautil.hpp
+++ b/src/scripting/luautil.hpp
@@ -80,7 +80,7 @@ template <typename T> void pushSTLContainer(lua_State *s, const std::vector<T> &
for (int key = 0; key < len; key++)
{
push(s, key+1);
- push(s, container.at(key).c_str());
+ push(s, container.at(key));
lua_settable(s, table);
}
}
@@ -96,8 +96,8 @@ template <typename Tkey, typename Tval> void pushSTLContainer(lua_State *s, cons
for (int key = 1; key <= len; key++)
{
- push(s, i->first.c_str());
- push(s, i->second.c_str());
+ push(s, i->first);
+ push(s, i->second);
lua_settable(s, table);
i++;
}