summaryrefslogtreecommitdiff
path: root/plugins/Dfusion
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-03-31 12:11:43 +0400
committerAlexander Gavrilov2012-03-31 12:11:43 +0400
commit9384f0c842f817bf810b34e44bfa3be913e7e3fc (patch)
treee5c69e7f4492ad4b8983e458471ac904a5364d88 /plugins/Dfusion
parent10b610669fe90bbe32ca412e74234b74d1293f6c (diff)
downloaddfhack-9384f0c842f817bf810b34e44bfa3be913e7e3fc.tar.gz
dfhack-9384f0c842f817bf810b34e44bfa3be913e7e3fc.tar.bz2
dfhack-9384f0c842f817bf810b34e44bfa3be913e7e3fc.tar.xz
Update lua to 5.2 and fix obvious breakage due to obsolete api.
Diffstat (limited to 'plugins/Dfusion')
-rw-r--r--plugins/Dfusion/include/luamain.h4
-rw-r--r--plugins/Dfusion/include/lune.h5
-rw-r--r--plugins/Dfusion/src/luamain.cpp10
-rw-r--r--plugins/Dfusion/src/luaxx.cc20
4 files changed, 25 insertions, 14 deletions
diff --git a/plugins/Dfusion/include/luamain.h b/plugins/Dfusion/include/luamain.h
index eaff9758..37940743 100644
--- a/plugins/Dfusion/include/luamain.h
+++ b/plugins/Dfusion/include/luamain.h
@@ -31,8 +31,8 @@ namespace lua
//dumps lua function trace, useless unless called from lua.
string DebugDump(lua::state &L);
//register functions, first registers into global scope, second into current table
- void RegFunctions(lua::state &L,luaL_reg const *arr);
- void RegFunctionsLocal(lua::state &L,luaL_reg const *arr);
+ void RegFunctions(lua::state &L,luaL_Reg const *arr);
+ void RegFunctionsLocal(lua::state &L,luaL_Reg const *arr);
}
diff --git a/plugins/Dfusion/include/lune.h b/plugins/Dfusion/include/lune.h
index b48a594a..87046474 100644
--- a/plugins/Dfusion/include/lune.h
+++ b/plugins/Dfusion/include/lune.h
@@ -139,9 +139,8 @@ public:
// store method table in globals so that
// scripts can add functions written in Lua.
- lua_pushstring(L, T::className);
lua_pushvalue(L, methods);
- lua_settable(L, LUA_GLOBALSINDEX);
+ lua_setglobal(L, T::className);
lua_pushliteral(L, "__metatable");
lua_pushvalue(L, methods);
@@ -212,7 +211,7 @@ public:
userdataType *ud =
static_cast<userdataType*>(luaL_checkudata(L, narg, T::className)); //TODO FIX THIs..
//(lua_touserdata(L, narg));//
- if(!ud) luaL_typerror(L, narg, T::className);
+ if(!ud) luaL_error(L, "Bad argument %d: expected type %s", narg, T::className);
return ud->pT; // pointer to T object
}
protected:
diff --git a/plugins/Dfusion/src/luamain.cpp b/plugins/Dfusion/src/luamain.cpp
index 3f9cfdad..36ecb98b 100644
--- a/plugins/Dfusion/src/luamain.cpp
+++ b/plugins/Dfusion/src/luamain.cpp
@@ -23,7 +23,7 @@ int lua_Ver_Lua(lua_State *L)
}
-static const struct luaL_reg lua_basic_lib [] =
+static const struct luaL_Reg lua_basic_lib [] =
{
{"getluaver", lua_Ver_Lua},
{NULL, NULL} /* sentinel */
@@ -34,9 +34,9 @@ void lua::RegBasics(lua::state &L)
RegFunctions(L,lua_basic_lib);
}
-void lua::RegFunctions(lua::state &L,luaL_reg const*arr)
+void lua::RegFunctions(lua::state &L,luaL_Reg const*arr)
{
- luaL_reg const *cur=arr;
+ luaL_Reg const *cur=arr;
while(cur->name!=NULL)
{
lua_pushcfunction(L, cur->func);
@@ -45,9 +45,9 @@ void lua::RegFunctions(lua::state &L,luaL_reg const*arr)
cur++;
}
}
-void lua::RegFunctionsLocal(lua::state &L,luaL_reg const*arr)
+void lua::RegFunctionsLocal(lua::state &L,luaL_Reg const*arr)
{
- luaL_reg const *cur=arr;
+ luaL_Reg const *cur=arr;
while(cur->name!=NULL)
{
lua_pushcfunction(L, cur->func);
diff --git a/plugins/Dfusion/src/luaxx.cc b/plugins/Dfusion/src/luaxx.cc
index a8ed0ca3..fe2e2704 100644
--- a/plugins/Dfusion/src/luaxx.cc
+++ b/plugins/Dfusion/src/luaxx.cc
@@ -215,7 +215,11 @@ namespace lua
template<>
std::string state::as(std::string default_value, int index) {
if (lua_isstring(L, index))
- return std::string(lua_tostring(L, index), lua_strlen(L, index));
+ {
+ size_t len;
+ const char *str = lua_tolstring(L, index, &len);
+ return std::string(str, len);
+ }
else
return default_value;
}
@@ -674,7 +678,7 @@ namespace lua
* @returns the length of the indicated value
*/
size_t state::objlen(int index) {
- return lua_objlen(L, index);
+ return lua_rawlen(L, index);
}
/** Get the value at index as a bool.
@@ -715,7 +719,11 @@ namespace lua
template<>
state& state::to(std::string& string, int index) {
if (lua_isstring(L, index))
- string.replace(0, std::string::npos, lua_tostring(L, index), lua_strlen(L, index));
+ {
+ size_t len;
+ const char *str = lua_tolstring(L, index, &len);
+ string.replace(0, std::string::npos, str, len);
+ }
else
throw bad_conversion("Cannot convert value to string");
@@ -755,7 +763,11 @@ namespace lua
template<>
std::string state::as(int index) {
if (lua_isstring(L, index))
- return std::string(lua_tostring(L, index), lua_strlen(L, index));
+ {
+ size_t len;
+ const char *str = lua_tolstring(L, index, &len);
+ return std::string(str, len);
+ }
else
throw bad_conversion("Cannot convert value to string");
}