diff options
author | Oliver Schneider <oliver@assarbad.net> | 2012-11-09 06:34:38 +0400 |
---|---|---|
committer | Oliver Schneider <oliver@assarbad.net> | 2012-11-09 06:34:38 +0400 |
commit | fe9407080643f1e5889b4bd30a42a358a60a02f9 (patch) | |
tree | c2a9daf4de24957752c8849c1b08167974bbead5 /sandbox | |
parent | 79c40bf4349dcb58c536dc0b700d6c697f3ad2f1 (diff) |
- Experimenting with the resource loader, still missing some connecting dots ...
Diffstat (limited to 'sandbox')
-rw-r--r-- | sandbox/luaconf/lua_conf.cpp | 136 | ||||
-rw-r--r-- | sandbox/luaconf/lua_conf.lua | 41 | ||||
-rw-r--r-- | sandbox/luaconf/lua_conf.rc | 3 | ||||
-rw-r--r-- | sandbox/luaconf/lua_conf.vcproj | 4 |
4 files changed, 93 insertions, 91 deletions
diff --git a/sandbox/luaconf/lua_conf.cpp b/sandbox/luaconf/lua_conf.cpp index a385a14..5f9de14 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,61 +11,61 @@ 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); - fprintf(stderr, "%s\n", msg); - fflush(stderr); - } - - - static int report (lua_State *L, int status) - { - if (status && !lua_isnil(L, -1)) { - const char *msg = lua_tostring(L, -1); - if (msg == NULL) msg = "(error object is not a string)"; - l_message(__FILE__, msg); - lua_pop(L, 1); - } - 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 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);
+ fprintf(stderr, "%s\n", msg);
+ fflush(stderr);
+ }
+
+
+ static int report (lua_State *L, int status)
+ {
+ if (status && !lua_isnil(L, -1)) {
+ const char *msg = lua_tostring(L, -1);
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(__FILE__, msg);
+ lua_pop(L, 1);
+ }
+ 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 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);
}
}
@@ -75,33 +76,24 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) lua_State* L = luaWDS_open();
if(L)
{
- const char* _dostring = "function dumptable(T,t)\n\
- print '--------------------------'\n\
- print(T)\n\
- print '--------------------------'\n\
- for k,v in pairs(t)do print(k,v) end\n\
- end\n\
- \n\
- dumptable('package', package)\n\
- dumptable('package.preload', package.preload)\n\
- dumptable('package.loaded', package.loaded)\n\
- dumptable('package.loaders', package.loaders)\n\
- dumptable('package.loaded._G', package.loaded._G)\n\
- print '--------------------------'\n\
- print('_G = ', _G)\n\
- print('package.loaded._G = ', package.loaded._G)\n\
- ";
- dostring(L, _dostring);
- fprintf(stderr, "--------------------------\n");
+ int stackTop = lua_gettop(L);
+ fprintf(stderr, "[STACK TOP] %i (line %i)\n", stackTop, __LINE__);
+ enumerateEmbeddedLuaScripts(L);
+ fprintf(stderr, "[STACK TOP] %i (line %i)\n", stackTop, __LINE__);
int ret = luaL_dofile(L, "..\\lua_conf.lua");
+ fprintf(stderr, "[STACK TOP] %i (line %i)\n", stackTop, __LINE__);
if(ret)
{
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1); /* pop error message from the stack */
+ fprintf(stderr, "[STACK TOP] %i (line %i)\n", stackTop, __LINE__);
lua_close(L);
+ fprintf(stderr, "[STACK TOP] %i (line %i)\n", stackTop, __LINE__);
return EXIT_FAILURE;
}
+ fprintf(stderr, "[STACK TOP] %i (line %i)\n", stackTop, __LINE__);
lua_close(L);
+ fprintf(stderr, "[STACK TOP] %i (line %i)\n", stackTop, __LINE__);
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
diff --git a/sandbox/luaconf/lua_conf.lua b/sandbox/luaconf/lua_conf.lua index c35e3cd..4538355 100644 --- a/sandbox/luaconf/lua_conf.lua +++ b/sandbox/luaconf/lua_conf.lua @@ -12,34 +12,37 @@ else print "I'm NOT a WOW64 process"
end
-print "-----------------"
+print '--------------------------'
function test_loader(...)
- print(...)
+ print("LOADER FUNC: ", ...)
local mod = {}
package.loaded[...] = mod
return mod
end
-
package.preload["mytest"] = test_loader
require "mytest"
-for k,v in pairs(package.loaded)do print(k,v) end
---[[
-local function load(modulename)
- local errmsg = ""
- -- Find source
- local modulepath = string.gsub(modulename, "%.", "/")
- for path in string.gmatch(package.path, "([^;]+)") do
- local filename = string.gsub(path, "%?", modulepath)
- local file = io.open(filename, "rb")
- if file then
- -- Compile and return the module
- return assert(loadstring(assert(file:read("*a")), filename))
+function dumptable(T,t)
+ print '--------------------------'
+ print(T)
+ print '--------------------------'
+ for k,v in pairs(t)do print(k,v) end
+end
+
+dumptable('package', package)
+dumptable('package.preload', package.preload)
+dumptable('package.loaded', package.loaded)
+dumptable('package.loaders', package.loaders)
+dumptable('package.loaded._G', package.loaded._G)
+dumptable('package.loaded.winreg', package.loaded.winreg)
+if winres then
+ dumptable('winres', winres)
+ if winres.scripts then
+ dumptable('winres.scripts', winres.scripts)
end
- errmsg = errmsg.."\n\tno file '"..filename.."' (checked with custom loader)"
- end
- return errmsg
end
-]]
\ No newline at end of file +print '--------------------------'
+print('_G = ', _G)
+print('package.loaded._G = ', package.loaded._G)
diff --git a/sandbox/luaconf/lua_conf.rc b/sandbox/luaconf/lua_conf.rc index 114c303..2856341 100644 --- a/sandbox/luaconf/lua_conf.rc +++ b/sandbox/luaconf/lua_conf.rc @@ -54,7 +54,10 @@ END #endif
/////////////////////////////////////////////////////////////////////////////
+#include "modules/w32resembed.h"
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+lua_conf LUA "../../sandbox/luaconf/lua_conf.lua"
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
diff --git a/sandbox/luaconf/lua_conf.vcproj b/sandbox/luaconf/lua_conf.vcproj index 92e017c..6e47726 100644 --- a/sandbox/luaconf/lua_conf.vcproj +++ b/sandbox/luaconf/lua_conf.vcproj @@ -62,6 +62,7 @@ <Tool
Name="VCResourceCompilerTool"
AdditionalOptions="/nologo"
+ AdditionalIncludeDirectories="$(ProjectDir)\..\..\lua\src"
/>
<Tool
Name="VCPreLinkEventTool"
@@ -144,6 +145,7 @@ <Tool
Name="VCResourceCompilerTool"
AdditionalOptions="/nologo"
+ AdditionalIncludeDirectories="$(ProjectDir)\..\..\lua\src"
/>
<Tool
Name="VCPreLinkEventTool"
@@ -223,6 +225,7 @@ <Tool
Name="VCResourceCompilerTool"
AdditionalOptions="/nologo"
+ AdditionalIncludeDirectories="$(ProjectDir)\..\..\lua\src"
/>
<Tool
Name="VCPreLinkEventTool"
@@ -305,6 +308,7 @@ <Tool
Name="VCResourceCompilerTool"
AdditionalOptions="/nologo"
+ AdditionalIncludeDirectories="$(ProjectDir)\..\..\lua\src"
/>
<Tool
Name="VCPreLinkEventTool"
|