diff options
author | pixel <pixel> | 2006-01-31 17:02:38 +0000 |
---|---|---|
committer | pixel <pixel> | 2006-01-31 17:02:38 +0000 |
commit | 6daac4eb3604736e20e8af5733f698eb144f0c2a (patch) | |
tree | 7a684f120b20e0aae0ecbedcaad480cdae581200 /lib/BLua.cc | |
parent | 6634b5d65d21b826830d7601178453a0a3084e8d (diff) |
Way too much changes - all over.
Diffstat (limited to 'lib/BLua.cc')
-rw-r--r-- | lib/BLua.cc | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index 14ab466..58aef96 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -1,6 +1,6 @@ /* * Baltisot - * Copyright (C) 1999-2003 Nicolas "Pixel" Noble + * Copyright (C) 1999-2006 Nicolas "Pixel" Noble * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.cc,v 1.33 2005-12-01 14:29:20 pixel Exp $ */ +/* $Id: BLua.cc,v 1.34 2006-01-31 17:02:39 pixel Exp $ */ #include <stdlib.h> #include "BLua.h" @@ -73,6 +73,8 @@ class LuaStatics : public Base { static int getglobal(lua_State *); static int dumpvars(lua_State *); + + static int iconv(lua_State *); }; std::map<lua_State *, Lua *> Lua::lualist; @@ -267,6 +269,26 @@ int LuaStatics::dumpvars(lua_State * _L) { return 0; } +int LuaStatics::iconv(lua_State * _L) { + Lua * L = Lua::find(_L); + int n = L->gettop(); + String str, from, to; + + if ((n != 3) || !L->isstring(1) || !L->isstring(2) || !L->isstring(3)) { + L->error("Incorrect arguments to function `string.iconv'"); + } + + str = L->tostring(1); + from = L->tostring(2); + to = L->tostring(3); + + str.iconv(from, to); + + L->push(str); + + return 1; +} + Lua::Lua() : L(lua_open()) { lualist[L] = this; lua_atpanic(L, LuaStatics::luapanic); @@ -318,6 +340,9 @@ void Lua::open_io() { void Lua::open_string() { luaopen_string(L); + push("iconv"); + push(LuaStatics::iconv); + settable(); lua_pop(L, 1); } @@ -589,6 +614,11 @@ int LuaStatics::putF(lua_State * L, const void * p, size_t size, void * ud) { return lf->f->write(p, size) == size; } +String Lua::escape_string(const String & s) { + /* TODO */ + return s; +} + void Lua::load(Handle * h, bool docall) throw (GeneralException) { LoadF lf; int status; @@ -662,7 +692,7 @@ void Lua::dumpvars_r(Handle * h, int i, int depth) throw (GeneralException) { t = String("[") + (lua_toboolean(L, -2) ? "true" : "false") + "] = "; break; case LUA_TSTRING: - t = lua_tostring(L, -2) + String(" = "); + t = "[\"" + escape_string(lua_tostring(L, -2)) + String("\"] = "); break; case LUA_TTABLE: t = "-- [a table]\n"; @@ -703,7 +733,7 @@ void Lua::dumpvars_r(Handle * h, int i, int depth) throw (GeneralException) { (*h) << (lua_toboolean(L, -1) ? "true" : "false") << ",\n"; break; case LUA_TSTRING: - (*h) << "\"" << lua_tostring(L, -1) << "\",\n"; + (*h) << "\"" << escape_string(lua_tostring(L, -1)) << "\",\n"; break; case LUA_TTABLE: (*h) << "{\n"; |