diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-11-29 21:50:29 +0100 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-11-29 21:50:29 +0100 |
commit | 977c77aa085b10e48505c861f5d47b3e881170e2 (patch) | |
tree | 985647f8f00798d7e2e499305b66d222242e6b40 | |
parent | 0fd6cb126b6238d2cbc01bed12ff043f45039c76 (diff) | |
parent | c99762a8980e691bab478f67b56b3fde56694e86 (diff) |
Merge branch 'master' of /pub/repo.git/Baltisot
-rw-r--r-- | include/LuaTask.h | 6 | ||||
-rw-r--r-- | lib/LuaTask.cc | 16 | ||||
-rw-r--r-- | lib/String.cc | 11 | ||||
-rw-r--r-- | lib/ajaxlib.lua | 14 | ||||
-rw-r--r-- | lib/dblib.lua | 2 |
5 files changed, 27 insertions, 22 deletions
diff --git a/include/LuaTask.h b/include/LuaTask.h index 3695dcb..ae18d40 100644 --- a/include/LuaTask.h +++ b/include/LuaTask.h @@ -21,7 +21,7 @@ #define __LUATASK_H__ #include <vector> -#include <hashtab.h> +#include <map> #include <Task.h> #include <Buffer.h> @@ -50,12 +50,12 @@ class LuaTask : public Task { String task; bool destroy_VM; - static htab * h; + static std::map<Lua *, LuaTask *> h; }; class LuaTaskMan : public LuaObject { public: static void pushstatics(Lua *) throw (GeneralException); -}; +}; #endif 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, ...) |