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

luawin_dllerror.c « src - github.com/windirstat/lua-winreg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d661083040adb0fbbe4141d561db3abeee23fc5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "luawin_dllerror.h"
#include "stdmacro.h"
#include "luamacro.h"
#include "win_trace.h"
#define lgk_dllerror	"__dll_error"

#ifndef NDEBUG
void lua_dllerror(lua_State *L, DWORD dwErr, const char * exp, const char * file, int line){
#else
void lua_dllerror(lua_State *L, DWORD dwErr){
#endif
/*
if lgk_dllerror is present in global env and equal to false dont raise error!
*/
	lua_getglobal(L, lgk_dllerror);

	if(lua_isrealfalse(L, -1)){
		WIN_TRACEA("lua_dllerror:false");
	}else{
		CHAR chbuf[1024];
		int c;
		if(dwErr == 0)dwErr = GetLastError();
		c = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), chbuf, 1024, NULL);
		// remove trailing spaces
		if (c > 0 && c < 1024) {
			while(--c > 1 && ISSPACE(chbuf[c]))chbuf[c] = '\0';
		}
		lua_pushfstring(L, "%s\ncode: %d\n", chbuf, dwErr);
#ifndef NDEBUG
		if(file){
			lua_pushfstring(L, "file: %s\nline: %d\n", file, line);
			lua_concat(L, 2);
		}
		if(exp){
			lua_pushfstring(L, "expr: %s\n", exp);
			lua_concat(L, 2);
		}
#endif
		if(lua_isfunction(L, -2)){
			WIN_TRACEA("lua_dllerror:function");
			lua_call(L, 1, 0);
		}else{
			WIN_TRACEA("lua_dllerror:true");
			lua_error(L);
		}
	}
}