From 4d85f55a6d65420955a2d1e1f02b17d7403c527d Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 6 Jun 2010 18:25:55 +0100 Subject: [PATCH] Lua log and debug functions --- src/LuaWrap.cpp | 24 ++++++++++++++++++++++++ src/Main.cpp | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/LuaWrap.cpp b/src/LuaWrap.cpp index 73b6a28..6b27bf2 100644 --- a/src/LuaWrap.cpp +++ b/src/LuaWrap.cpp @@ -25,6 +25,26 @@ extern "C" { #include } +static int lua_debug(lua_State *L) +{ + const char *s = luaL_checkstring(L, -1); + if (s != NULL) + debug() << s; + + return 0; +} + +static int lua_log(lua_State *L) +{ + return 0; +} + +static luaL_Reg luaFuncs[] = { + { "debug", lua_debug }, + { "log", lua_log }, + { NULL, NULL } +}; + class LuaWrap : public ILua { public: LuaWrap(); @@ -41,6 +61,10 @@ LuaWrap::LuaWrap() if ((luaVM = lua_open()) == NULL) throw runtime_error("Failed to initialise Lua"); + + lua_pushvalue(luaVM, LUA_GLOBALSINDEX); + luaL_register(luaVM, NULL, luaFuncs); + lua_pop(luaVM, 1); } LuaWrap::~LuaWrap() diff --git a/src/Main.cpp b/src/Main.cpp index 9d43fa2..1834019 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -106,7 +106,7 @@ int main(int argc, char** argv) ::window = makeSDLWindow(); ILuaPtr lua = getLua(); - lua->eval("debug(\"hello\")"); + lua->eval("debug(\"yahyahyah\")"); IScreenPtr screen; if (::action == "edit") { -- 2.39.2