summaryrefslogtreecommitdiff
path: root/lib/BLua.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/BLua.cc')
-rw-r--r--lib/BLua.cc39
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc
index ac1f8e8..ab54be3 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.48 2007-05-30 22:36:31 pixel Exp $ */
+/* $Id: BLua.cc,v 1.49 2007-05-31 13:26:52 pixel Exp $ */
#include <stdlib.h>
#include "BLua.h"
@@ -31,6 +31,12 @@
#undef isnumber
+void LuaPrinter::puts(const char * msg) {
+ fputs(msg, stdout);
+}
+
+LuaPrinter default_lua_printer;
+
extern "C" {
void do_lua_lock(lua_State * __L) {
Lua * L;
@@ -81,6 +87,8 @@ class LuaStatics : public Base {
static int mkdir(lua_State *);
static int globalindex(lua_State *);
+
+ static int print(lua_State *);
};
std::map<lua_State *, Lua *> Lua::lualist;
@@ -317,6 +325,24 @@ int LuaStatics::mkdir(lua_State * _L) {
return 0;
}
+int LuaStatics::print(lua_State * _L) {
+ Lua * L = Lua::find(_L);
+
+ int n = L->gettop(); /* number of arguments */
+ int i;
+ for (i = 1; i <= n; i++) {
+ const char *s;
+ s = lua_tostring(_L, i); /* get result */
+ if (s == NULL)
+ L->error("`tostring' must return a string to `print'");
+ if (i > 1) fputs("\t", stdout);
+ L->puts(s);
+ L->pop(); /* pop result */
+ }
+ L->puts("\n");
+ return 0;
+}
+
int LuaStatics::callwrap(lua_State * __L, lua_CFunction func) {
Lua * L = Lua::find(__L);
int n;
@@ -386,6 +412,8 @@ void Lua::setup_state(lua_State *) {
lua_setcallwrap(L, LuaStatics::callwrap);
lua_setcreatehook(L, LuaStatics::createhook);
lua_setdestroyhook(L, LuaStatics::destroyhook);
+
+ lprinter = &default_lua_printer;
}
Lua::Lua() : L(lua_open()), _protected(false), _is_thread(false) {
@@ -399,6 +427,7 @@ Lua::Lua() : L(lua_open()), _protected(false), _is_thread(false) {
declarefunc("hex", LuaStatics::hex);
declarefunc("getglobal", LuaStatics::getglobal);
declarefunc("dumpvars", LuaStatics::dumpvars);
+ declarefunc("print", LuaStatics::print);
push("BLUA_THREADS");
newtable();
settable(LUA_REGISTRYINDEX);
@@ -415,6 +444,14 @@ Lua::Lua(lua_State * __L) : L(__L), _protected(false), _is_thread(true) {
}
+void Lua::SetPrinter(LuaPrinter * lp) {
+ lprinter = lp;
+}
+
+void Lua::puts(const char * msg) {
+ lprinter->puts(msg);
+}
+
Lua * Lua::Father() {
return father ? father : this;
}