summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2008-07-05 06:24:05 +0000
committerpixel <pixel>2008-07-05 06:24:05 +0000
commitde8be583fd45cefd61287ef33b148efba0d6ec98 (patch)
tree049257b2f510daf08faa7ecdf0202c3dc6b8a70d
parent7bb6385ee34141771aac6e3e6e348c213d92f451 (diff)
Removing the useless lock/unlock code from the Lua interface.
-rw-r--r--lib/BLua.cc56
1 files changed, 1 insertions, 55 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc
index ec62a8e..a8751be 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.60 2008-05-20 18:11:51 pixel Exp $ */
+/* $Id: BLua.cc,v 1.61 2008-07-05 06:24:05 pixel Exp $ */
#include <stdlib.h>
#include "BLua.h"
@@ -95,10 +95,8 @@ std::map<lua_State *, Lua *> Lua::lualist;
int LuaStatics::luaerror(lua_State * __L) {
Lua * L = Lua::find(__L);
- L->lock();
L->push_lua_context();
L->showerror();
- L->unlock();
return 0;
}
@@ -110,10 +108,8 @@ int LuaStatics::trueluapanic(lua_State * __L) throw (GeneralException) {
Lua * L = Lua::find(__L);
if (L->is_protected())
return 0; // luaerror will get it for us...
- L->lock();
L->push_lua_context();
L->showerror();
- L->unlock();
throw LuaException("Unprotected error running Lua code, bailing out; expect unstable lua environment.");
}
@@ -254,10 +250,8 @@ int LuaStatics::getglobal(lua_State * _L) {
Buffer b;
b << "return " + L->tostring();
- L->lock();
L->load(&b, false);
L->call(0, 1);
- L->unlock();
return 1;
}
@@ -489,7 +483,6 @@ Lua::Lua(const Lua & l) throw (GeneralException) {
}
void Lua::open_base() {
- lock();
luaopen_base(L);
push("mkdir");
push(LuaStatics::mkdir);
@@ -498,82 +491,63 @@ void Lua::open_base() {
push("mkdir");
push(LuaStatics::mkdir);
settable(LUA_GLOBALSINDEX);
- unlock();
}
void Lua::open_table() {
- lock();
luaopen_table(L);
lua_pop(L, 1);
- unlock();
}
void Lua::open_io(bool safe) {
- lock();
luaopen_io(L);
lua_pop(L, 1);
- unlock();
}
void Lua::open_string() {
- lock();
luaopen_string(L);
push("iconv");
push(LuaStatics::iconv);
settable();
lua_pop(L, 1);
- unlock();
}
void Lua::open_math() {
- lock();
luaopen_math(L);
lua_pop(L, 1);
- unlock();
}
void Lua::open_debug() {
- lock();
luaopen_debug(L);
lua_pop(L, 1);
- unlock();
}
void Lua::open_dir() {
- lock();
luaopen_dir(L);
lua_pop(L, 1);
- unlock();
}
void Lua::declarefunc(const String & name, lua_CFunction f, int i) {
- lock();
lua_pushstring(L, name.to_charp());
lua_pushcfunction(L, f);
lua_settable(L, i);
- unlock();
}
void Lua::call(const String & f, int i, int nargs, int nresults) {
- lock();
lua_pushstring(L, f.to_charp());
lua_gettable(L, i);
lua_insert(L, -1 - nargs - nresults);
call(nargs, nresults);
- unlock();
}
void Lua::call(int nargs, int nresults) throw(GeneralException) {
int r;
- lock();
lua_pushcfunction(L, LuaStatics::luaerror);
lua_insert(L, 1);
_protected = true;
r = lua_pcall(L, nargs, nresults, 1);
_protected = false;
lua_remove(L, 1);
- unlock();
switch(r) {
case 0:
@@ -684,10 +658,8 @@ void Lua::getglobal(const String & name) throw (GeneralException) {
b << "return " + name;
try {
- lock();
load(&b, false);
call(0, 1);
- unlock();
}
catch (LuaException &) {
throw LuaException("Error finding global variable `" + name + "'");
@@ -766,7 +738,6 @@ bool Lua::islightuserdata(int i) {
bool Lua::isobject(int i) {
bool r = false;
- lock();
if (istable(i)) {
push("__obj");
gettable(i);
@@ -775,7 +746,6 @@ bool Lua::isobject(int i) {
} else {
r = isnil(i);
}
- unlock();
return r;
}
@@ -873,8 +843,6 @@ void Lua::load(Handle * h, bool docall) throw (GeneralException) {
lf.f = h;
- if (docall)
- lock();
status = lua_load(L, LuaStatics::getF, &lf, h->GetName().to_charp());
if (status) {
@@ -885,7 +853,6 @@ void Lua::load(Handle * h, bool docall) throw (GeneralException) {
if (docall) {
call();
- unlock();
}
}
@@ -893,9 +860,6 @@ void Lua::load(const String & s, bool docall) throw (GeneralException) {
const char * buf = s.to_charp();
int status;
- if (docall)
- lock();
-
status = luaL_loadbuffer(L, buf, s.strlen(), buf);
if (status) {
@@ -906,7 +870,6 @@ void Lua::load(const String & s, bool docall) throw (GeneralException) {
if (docall) {
call();
- unlock();
}
}
@@ -1079,7 +1042,6 @@ int Lua::yield(int nresults) {
bool Lua::resume(int nargs) throw (GeneralException) {
int r;
- lock();
_protected = true;
r = lua_resume(L, nargs);
_protected = false;
@@ -1089,8 +1051,6 @@ bool Lua::resume(int nargs) throw (GeneralException) {
showerror();
}
- unlock();
-
switch(r) {
case 0:
return false;
@@ -1112,10 +1072,8 @@ bool Lua::resume(int nargs) throw (GeneralException) {
bool Lua::resume(Handle * h, int nargs) {
bool r;
- lock();
load(h, false);
r = resume(nargs);
- unlock();
return r;
}
@@ -1123,10 +1081,8 @@ bool Lua::resume(Handle * h, int nargs) {
bool Lua::resume(const String & s, int nargs) {
bool r;
- lock();
load(s, false);
r = resume(nargs);
- unlock();
return r;
}
@@ -1230,17 +1186,14 @@ void LuaObject::push(Lua * L) throw (GeneralException) {
if (pushed && wantdestruct) {
throw GeneralException("Error: object is owned by the LUA script and can not be pushed.");
}
- L->lock();
L->newtable();
pushmembers(L);
- L->unlock();
pushed = true;
}
void LuaObject::pushme(Lua * L, void * o, const String & objname, bool obj) {
void ** u;
bool * b;
- L->lock();
L->push("__obj");
u = (void **) L->newuser(sizeof(o) + sizeof(bool));
*u = o;
@@ -1252,7 +1205,6 @@ void LuaObject::pushme(Lua * L, void * o, const String & objname, bool obj) {
L->push(objname);
L->settable(-3, true);
}
- L->unlock();
}
void * LuaObject::getme(Lua * L, int i) {
@@ -1276,15 +1228,12 @@ void * LuaObject::getme(Lua * L, int i) {
}
void LuaObject::pushit(Lua * L, const String & s, lua_CFunction f) {
- L->lock();
L->push(s);
L->push(f);
L->settable(-3, true);
- L->unlock();
}
void LuaObject::pushmeta(Lua * L, const String & s, lua_CFunction f) {
- L->lock();
if (!L->getmetatable()) {
L->newtable();
}
@@ -1292,21 +1241,18 @@ void LuaObject::pushmeta(Lua * L, const String & s, lua_CFunction f) {
L->push(f);
L->settable();
L->setmetatable();
- L->unlock();
}
void LuaObject::pushdestruct(Lua * L) throw (GeneralException) {
if (pushed) {
throw GeneralException("Error: can't push destructor, object already pushed");
}
- L->lock();
push(L);
L->push("__obj");
L->gettable(-2, true);
pushmeta(L, "__gc", LuaStatics::collector);
L->pop();
pushit(L, "destroy", LuaStatics::destructor);
- L->unlock();
wantdestruct = true;
}