Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Schneider <oliver@assarbad.net>2013-11-21 21:40:30 +0400
committerOliver Schneider <oliver@assarbad.net>2013-11-21 21:40:30 +0400
commitb296facb6854815e454e04f6bb1ca741893cead7 (patch)
treebb5def8addff577198f976e98efd64f37b49ac76 /sandbox
parentc22e6af6393168b5099b1c35eb468c5c42533483 (diff)
parent7e1c825fac09e3dbbd5ab4bc01253eb37d120bfd (diff)
Merged with changes from another repo
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/luaconf/hello.lua2
-rw-r--r--sandbox/luaconf/lua_conf.cpp62
-rw-r--r--sandbox/luaconf/lua_conf.lua10
3 files changed, 57 insertions, 17 deletions
diff --git a/sandbox/luaconf/hello.lua b/sandbox/luaconf/hello.lua
index 16cac19..99bb1dc 100644
--- a/sandbox/luaconf/hello.lua
+++ b/sandbox/luaconf/hello.lua
@@ -2,5 +2,5 @@
-- Declare the functions you want in your module
function hello()
- print ("Hello WORLD, module")
+print "Hello world"
end
diff --git a/sandbox/luaconf/lua_conf.cpp b/sandbox/luaconf/lua_conf.cpp
index 884f5fd..fdc4702 100644
--- a/sandbox/luaconf/lua_conf.cpp
+++ b/sandbox/luaconf/lua_conf.cpp
@@ -3,6 +3,7 @@
#include "stdafx.h"
#include "lua_conf.h"
+#include "modules/w32resembed.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -10,6 +11,25 @@
namespace
{
+ static int traceback (lua_State *L) {
+ if (!lua_isstring(L, 1)) /* 'message' not a string? */
+ return 1; /* keep it intact */
+ lua_getfield(L, LUA_GLOBALSINDEX, "debug");
+ if (!lua_istable(L, -1)) {
+ lua_pop(L, 1);
+ return 1;
+ }
+ lua_getfield(L, -1, "traceback");
+ if (!lua_isfunction(L, -1)) {
+ lua_pop(L, 2);
+ return 1;
+ }
+ lua_pushvalue(L, 1); /* pass error message */
+ lua_pushinteger(L, 2); /* skip this function and traceback */
+ lua_call(L, 2, 1); /* call debug.traceback */
+ return 1;
+ }
+
static void l_message (const char *pname, const char *msg)
{
if (pname) fprintf(stderr, "%s: ", pname);
@@ -28,6 +48,31 @@ namespace
}
return status;
}
+
+ static int docall (lua_State *L, int narg, int clear)
+ {
+ int status;
+ int base = lua_gettop(L) - narg; /* function index */
+ lua_pushcfunction(L, traceback); /* push traceback function */
+ lua_insert(L, base); /* put it under chunk and args */
+ status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
+ lua_remove(L, base); /* remove traceback function */
+ /* force a complete garbage collection in case of errors */
+ if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
+ return status;
+ }
+
+ static int dostring (lua_State *L, const char *s) {
+ const char *name = "dostring";
+ int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
+ return report(L, status);
+ }
+
+ static int dolibrary (lua_State *L, const char *name) {
+ lua_getglobal(L, "require");
+ lua_pushstring(L, name);
+ return report(L, lua_pcall(L, 1, 0, 0));
+ }
}
using namespace std;
@@ -37,21 +82,12 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
lua_State* L = luaWDS_open();
if(L)
{
- int ret = w32res_enumerateEmbeddedLuaScripts(L);
- if(ret)
- {
- luaL_error(L, "Failed to enum the resources (%d)", report(L, ret));
- lua_close(L);
- return EXIT_FAILURE;
- }
- if(lua_istable(L, -1))
- {
- lua_pop(L, 1);
- }
- ret = luaL_dofile(L, "lua_conf.lua");
+ //fprintf(stderr, "[STACK TOP] %i (line %i)\n", lua_gettop(L), __LINE__);
+ enumerateEmbeddedLuaScripts(L);
+ int ret = luaL_dofile(L, "..\\lua_conf.lua");
if(ret)
{
- luaL_error(L, "Failed to load lua_conf.lua (%d)", report(L, ret));
+ lua_pop(L, 1); /* pop error message from the stack */
lua_close(L);
return EXIT_FAILURE;
}
diff --git a/sandbox/luaconf/lua_conf.lua b/sandbox/luaconf/lua_conf.lua
index a21842e..648e1f4 100644
--- a/sandbox/luaconf/lua_conf.lua
+++ b/sandbox/luaconf/lua_conf.lua
@@ -24,9 +24,13 @@ if winres then
end
end
+for k,v in pairs(winres.scripts) do
+ package.preload[k:lower()] = function(...)
+ return winres.c_loader(k:upper())
+ end
+ package.preload[k:upper()] = package.preload[k:lower()]
+end
dumptable('package.preload', package.preload)
dumptable('winreg', winreg)
-x = require "helloworld"
+require "helloworld"
dumptable('package.loaded', package.loaded)
-dumptable('package.loaded.helloworld', x)
-x.hello()