summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/LuaTask.cc16
-rw-r--r--lib/String.cc11
-rw-r--r--lib/ajaxlib.lua14
-rw-r--r--lib/dblib.lua2
4 files changed, 24 insertions, 19 deletions
diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc
index ef1abf7..b475c5b 100644
--- a/lib/LuaTask.cc
+++ b/lib/LuaTask.cc
@@ -30,7 +30,7 @@
#include <CopyJob.h>
#endif
-htab * LuaTask::h = hcreate(1);
+std::map<Lua *, LuaTask *> LuaTask::h;
LuaTask::LuaTask(Lua * __L, const String & _cmd, bool _destroy_VM) : L(__L), cmd(_cmd), nargs(0), c(0), b(0), destroy_VM(_destroy_VM) {
LuaTask * top = gettop();
@@ -62,21 +62,11 @@ LuaTask::~LuaTask() {
}
LuaTask * LuaTask::gettop() {
- if (!hfind(h, (Uint8 *) &L, sizeof(L))) {
- hadd(h, (Uint8 *) &L, sizeof(L), 0);
- }
-
- return (LuaTask *) hstuff(h);
+ return h[L];
}
void LuaTask::settop(LuaTask * v) {
- if (!hfind(h, (Uint8 *) &L, sizeof(L)))
- return;
- if (v) {
- hstuff(h) = v;
- } else {
- hdel(h);
- }
+ h[L] = v;
}
String LuaTask::GetName() {
diff --git a/lib/String.cc b/lib/String.cc
index 14195f6..47315b6 100644
--- a/lib/String.cc
+++ b/lib/String.cc
@@ -276,8 +276,10 @@ String String::extract(size_t from, ssize_t to) const {
char * String::strdup(size_t from, ssize_t to) const {
char * r;
- r = Base::strdup(to_charp(from, to));
-
+ r = Base::strdup(to_charp(from, -1));
+ to -= from;
+ if ((to >= 0) && (to < (siz - from)))
+ r[to + 1] = 0;
return r;
}
@@ -386,9 +388,10 @@ const char & String::operator[](size_t i) const {
}
char & String::operator[](size_t i) throw (GeneralException) {
-
+ static char zero;
if (i >= siz) {
- throw GeneralException("operator[] on String out of bounds");
+ zero = 0;
+ return zero;
} else {
return str[i];
}
diff --git a/lib/ajaxlib.lua b/lib/ajaxlib.lua
index e51d74f..7a8a395 100644
--- a/lib/ajaxlib.lua
+++ b/lib/ajaxlib.lua
@@ -33,6 +33,18 @@ function ajax_escape(str)
return generic_escape(str, ajax_replacements)
end
+local function toajax(val)
+ local t = type(val)
+
+ if t == "nil" or t == "function" or t == "table" then
+ return ""
+ elseif t == "boolean" then
+ return v and "1" or "0"
+ else
+ return val
+ end
+end
+
function ajax_dump_table(t, out)
local k, v, vk, vv
@@ -43,7 +55,7 @@ function ajax_dump_table(t, out)
for k, v in pairs(t) do
out:write(k)
for vk, vv in pairs(v) do
- out:write("|" .. ajax_escape(vk) .. "=" .. ajax_escape(vv))
+ out:write("|" .. ajax_escape(toajax(vk)) .. "=" .. ajax_escape(toajax(vv)))
end
out:write("\n")
end
diff --git a/lib/dblib.lua b/lib/dblib.lua
index 271d5a1..64ce880 100644
--- a/lib/dblib.lua
+++ b/lib/dblib.lua
@@ -759,7 +759,7 @@ END;
count = function(t)
_luadb.iselect(true, t, {"COUNT(*) AS count"})
local row = t:nextrow()
- return row.count or row.COUNT
+ return ((row.count or row.COUNT) or 0) + 0
end,
gselect = function(t, ...)