diff options
-rw-r--r-- | lib/BLua.cc | 64 | ||||
-rw-r--r-- | lib/Buffer.cc | 7 | ||||
-rw-r--r-- | lib/LuaHandle.cc | 4 |
3 files changed, 62 insertions, 13 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index 36cc566..7c91bb1 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.cc,v 1.10 2003-12-08 15:12:56 pixel Exp $ */ +/* $Id: BLua.cc,v 1.11 2003-12-10 02:59:31 pixel Exp $ */ #include <lualib.h>
@@ -42,6 +42,8 @@ class LuaStatics : public Base { static int xorB(lua_State *);
static int notB(lua_State *);
static int hex(lua_State *);
+ static int shl(lua_State *);
+ static int shr(lua_State *);
};
std::map<lua_State *, Lua *> Lua::lualist;
@@ -58,7 +60,7 @@ int LuaStatics::trueluapanic(lua_State * L) throw (GeneralException) { int LuaStatics::andB(lua_State * _L) {
Lua * L = Lua::find(_L);
int n = L->gettop();
- int a, b;
+ Uint32 a, b;
if ((n != 2) && !L->isnumber(1) && !L->isnumber(2)) {
L->error("Incorrect arguments to function `andB'");
@@ -75,7 +77,7 @@ int LuaStatics::andB(lua_State * _L) { int LuaStatics::orB(lua_State * _L) {
Lua * L = Lua::find(_L);
int n = L->gettop();
- int a, b;
+ Uint32 a, b;
if ((n != 2) && !L->isnumber(1) && !L->isnumber(2)) {
L->error("Incorrect arguments to function `orB'");
@@ -92,7 +94,7 @@ int LuaStatics::orB(lua_State * _L) { int LuaStatics::xorB(lua_State * _L) {
Lua * L = Lua::find(_L);
int n = L->gettop();
- int a, b;
+ Uint32 a, b;
if ((n != 2) && !L->isnumber(1) && !L->isnumber(2)) {
L->error("Incorrect arguments to function `xorB'");
@@ -109,7 +111,7 @@ int LuaStatics::xorB(lua_State * _L) { int LuaStatics::notB(lua_State * _L) {
Lua * L = Lua::find(_L);
int n = L->gettop();
- int x;
+ Uint32 x;
if ((n != 1) && !L->isnumber()) {
L->error("Incorrect arguments to function `notB'");
@@ -122,6 +124,46 @@ int LuaStatics::notB(lua_State * _L) { return 1;
}
+int LuaStatics::shl(lua_State * _L) {
+ Lua * L = Lua::find(_L);
+ int n = L->gettop();
+ Uint32 a, b;
+
+ if ((n > 2) && !L->isnumber(1) && ((n == 2) && !L->isnumber(2))) {
+ L->error("Incorrect arguments to function `shl'");
+ }
+
+ a = L->tonumber(1);
+ if (n == 2)
+ b = L->tonumber(2);
+ else
+ b = 1;
+
+ L->push((lua_Number) (a << b));
+
+ return 1;
+}
+
+int LuaStatics::shr(lua_State * _L) {
+ Lua * L = Lua::find(_L);
+ int n = L->gettop();
+ Uint32 a, b;
+
+ if ((n > 2) && !L->isnumber(1) && ((n == 2) && !L->isnumber(2))) {
+ L->error("Incorrect arguments to function `shr'");
+ }
+
+ a = L->tonumber(1);
+ if (n == 2)
+ b = L->tonumber(2);
+ else
+ b = 1;
+
+ L->push((lua_Number) (a >> b));
+
+ return 1;
+}
+
int LuaStatics::hex(lua_State * _L) {
Lua * L = Lua::find(_L);
int n = L->gettop();
@@ -133,7 +175,7 @@ int LuaStatics::hex(lua_State * _L) { }
x = L->tonumber(1);
- String fmt = n == 2 ? L->tostring() : "%x";
+ String fmt = n == 2 ? L->tostring() : "%02x";
r.set(fmt.to_charp(), x);
L->push(r);
@@ -149,6 +191,8 @@ Lua::Lua() : L(lua_open()) { declarefunc("orB", LuaStatics::orB);
declarefunc("xorB", LuaStatics::xorB);
declarefunc("notB", LuaStatics::notB);
+ declarefunc("shl", LuaStatics::shl);
+ declarefunc("shr", LuaStatics::shr);
declarefunc("hex", LuaStatics::hex);
}
@@ -331,6 +375,8 @@ lua_Number Lua::tonumber(int i) { }
String Lua::tostring(int i) {
+ if (isnil(i))
+ return String();
return String(lua_tostring(L, i));
}
@@ -475,7 +521,7 @@ void LuaObject::push(Lua * L) throw (GeneralException) { void LuaObject::pushme(Lua * L, void * o) {
L->push("__obj");
L->push(o);
- L->settable();
+ L->settable(-3, true);
}
void * LuaObject::getme(Lua * L, int i) {
@@ -483,7 +529,7 @@ void * LuaObject::getme(Lua * L, int i) { if (L->istable(i)) {
L->push("__obj");
- L->gettable(i);
+ L->gettable(i, true);
if (!(r = L->touserdata())) {
L->error("Lua object already destroyed, or table is not an object.");
}
@@ -519,7 +565,7 @@ int LuaStatics::destructor(lua_State * _L) { delete b;
L->push("__obj");
L->push((void *) 0);
- L->settable();
+ L->settable(-3, true);
printm(M_INFO, "Destructing an object from LUA\n");
return 0;
}
diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 061064c..414d97c 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Buffer.cc,v 1.20 2003-12-04 04:09:02 pixel Exp $ */ +/* $Id: Buffer.cc,v 1.21 2003-12-10 02:59:31 pixel Exp $ */ #include <string.h> #ifdef HAVE_CONFIG_H @@ -88,7 +88,10 @@ bool Buffer::CanWrite() const { } String Buffer::GetName() const { - return "Buffer"; + if (seekable) + return "Buffer"; + else + return "Fifo"; } Buffer Buffer::operator=(const Buffer & b) { diff --git a/lib/LuaHandle.cc b/lib/LuaHandle.cc index 373066f..5d558d1 100644 --- a/lib/LuaHandle.cc +++ b/lib/LuaHandle.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaHandle.cc,v 1.7 2003-12-07 04:44:38 pixel Exp $ */ +/* $Id: LuaHandle.cc,v 1.8 2003-12-10 02:59:31 pixel Exp $ */ #include "LuaHandle.h"
@@ -476,7 +476,7 @@ int sLuaHandle::setz(lua_State * _L) { h->SetZ(z);
- return 1;
+ return 0;
}
int sLuaHandle::seek(lua_State * _L) {
|