summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-11-27 07:27:37 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-11-27 07:27:37 +0100
commit2158bd3e375e1185bd180219023a443a1a154957 (patch)
treed2010a579883175574063e2d3c838330b55bbfdd
parent070402f728067ed415b1e02d17823508b4dc2bcd (diff)
Adding SetFakeName system to help with the built-ins luas loads.
-rw-r--r--include/Buffer.h2
-rw-r--r--lib/Buffer.cc6
-rw-r--r--lib/LuaHandle.cc16
-rwxr-xr-xlib/genloadlib.sh1
4 files changed, 25 insertions, 0 deletions
diff --git a/include/Buffer.h b/include/Buffer.h
index a858617..98d0a4c 100644
--- a/include/Buffer.h
+++ b/include/Buffer.h
@@ -50,6 +50,7 @@ class Buffer : public Handle {
off_t wseek(off_t, int = SEEK_SET) throw (GeneralException);
off_t wtell() const;
void reset();
+ void SetFakeName(const String &);
const Byte * GetBuffer() const;
static int GetNbBuffer();
@@ -58,6 +59,7 @@ class Buffer : public Handle {
size_t realsiz, bufsiz, ptr, wptr;
bool seekable;
bool got_eof;
+ String fake_name;
static int nb_buffer;
};
diff --git a/lib/Buffer.cc b/lib/Buffer.cc
index 2d615b5..9b8aa8d 100644
--- a/lib/Buffer.cc
+++ b/lib/Buffer.cc
@@ -104,6 +104,8 @@ bool Buffer::CanWrite() const {
}
String Buffer::GetName() const {
+ if (fake_name.strlen() != 0)
+ return fake_name;
if (seekable)
return "Buffer";
else
@@ -240,3 +242,7 @@ void Buffer::reset() {
realsiz = bufsiz = ptr = wptr = 0;
got_eof = false;
}
+
+void Buffer::SetFakeName(const String & _fake_name) {
+ fake_name = _fake_name;
+}
diff --git a/lib/LuaHandle.cc b/lib/LuaHandle.cc
index ba66afc..4b6fd6e 100644
--- a/lib/LuaHandle.cc
+++ b/lib/LuaHandle.cc
@@ -78,6 +78,7 @@ class sLuaHandle : public Base {
static int bseek(lua_State * L);
static int btell(lua_State * L);
static int breset(lua_State * L);
+ static int setfakename(lua_State * L);
static int exists(lua_State * L);
static int get_nb_handles(lua_State * L);
static int get_nb_input(lua_State * L);
@@ -1090,6 +1091,20 @@ int sLuaHandle::breset(lua_State * __L) {
return 0;
}
+int sLuaHandle::setfakename(lua_State * __L) {
+ Lua * L = Lua::find(__L);
+ int n = L->gettop();
+ Buffer * h;
+
+ if ((n != 2) || !L->isstring(2)) {
+ L->error("Incorrect arguments to method `Buffer::setfakename'");
+ }
+
+ h = L->recast<Buffer>();
+ h->setfakename(L->tostring(2));
+ return 0;
+}
+
int sLuaHandle::exists(lua_State * __L) {
Lua * L = Lua::find(__L);
int n = L->gettop();
@@ -1132,6 +1147,7 @@ void LuaBuffer::pushmembers(Lua * L) {
pushit(L, "wtell", sLuaHandle::btell);
pushit(L, "wseek", sLuaHandle::bseek);
pushit(L, "reset", sLuaHandle::breset);
+ pushit(L, "setfakename", sLuaHandle::setfakename);
L->push("__handletype");
L->push("Buffer");
L->settable(-3, true);
diff --git a/lib/genloadlib.sh b/lib/genloadlib.sh
index c7231b1..c9b2c19 100755
--- a/lib/genloadlib.sh
+++ b/lib/genloadlib.sh
@@ -14,6 +14,7 @@ echo 'void LoadLuaLibs(Lua * L) {'
ls *.lua | while read f ; do
b=${f%%.*}
echo " Buffer ${b}_buff;"
+ echo " ${b}_buff.SetFakeName(\"@$b.lua\");"
echo " ${b}_buff.write($b, size_$b);"
echo " L->load(&${b}_buff);"
echo