aboutsummaryrefslogtreecommitdiff
path: root/src/lj_clib.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lj_clib.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/lj_clib.c b/src/lj_clib.c
index 4f17d578..8398e803 100644
--- a/src/lj_clib.c
+++ b/src/lj_clib.c
@@ -16,6 +16,7 @@
16#include "lj_cconv.h" 16#include "lj_cconv.h"
17#include "lj_cdata.h" 17#include "lj_cdata.h"
18#include "lj_clib.h" 18#include "lj_clib.h"
19#include "lj_strfmt.h"
19 20
20/* -- OS-specific functions ----------------------------------------------- */ 21/* -- OS-specific functions ----------------------------------------------- */
21 22
@@ -61,7 +62,7 @@ static const char *clib_extname(lua_State *L, const char *name)
61#endif 62#endif
62 ) { 63 ) {
63 if (!strchr(name, '.')) { 64 if (!strchr(name, '.')) {
64 name = lj_str_pushf(L, CLIB_SOEXT, name); 65 name = lj_strfmt_pushf(L, CLIB_SOEXT, name);
65 L->top--; 66 L->top--;
66#if LJ_TARGET_CYGWIN 67#if LJ_TARGET_CYGWIN
67 } else { 68 } else {
@@ -70,7 +71,7 @@ static const char *clib_extname(lua_State *L, const char *name)
70 } 71 }
71 if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] && 72 if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] &&
72 name[2] == CLIB_SOPREFIX[2])) { 73 name[2] == CLIB_SOPREFIX[2])) {
73 name = lj_str_pushf(L, CLIB_SOPREFIX "%s", name); 74 name = lj_strfmt_pushf(L, CLIB_SOPREFIX "%s", name);
74 L->top--; 75 L->top--;
75 } 76 }
76 } 77 }
@@ -171,11 +172,19 @@ LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,
171 const char *name) 172 const char *name)
172{ 173{
173 DWORD err = GetLastError(); 174 DWORD err = GetLastError();
175#if LJ_TARGET_XBOXONE
176 wchar_t wbuf[128];
177 char buf[128*2];
178 if (!FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
179 NULL, err, 0, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL) ||
180 !WideCharToMultiByte(CP_ACP, 0, wbuf, 128, buf, 128*2, NULL, NULL))
181#else
174 char buf[128]; 182 char buf[128];
175 if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, 183 if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
176 NULL, err, 0, buf, sizeof(buf), NULL)) 184 NULL, err, 0, buf, sizeof(buf), NULL))
185#endif
177 buf[0] = '\0'; 186 buf[0] = '\0';
178 lj_err_callermsg(L, lj_str_pushf(L, fmt, name, buf)); 187 lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, buf));
179} 188}
180 189
181static int clib_needext(const char *s) 190static int clib_needext(const char *s)
@@ -190,7 +199,7 @@ static int clib_needext(const char *s)
190static const char *clib_extname(lua_State *L, const char *name) 199static const char *clib_extname(lua_State *L, const char *name)
191{ 200{
192 if (clib_needext(name)) { 201 if (clib_needext(name)) {
193 name = lj_str_pushf(L, "%s.dll", name); 202 name = lj_strfmt_pushf(L, "%s.dll", name);
194 L->top--; 203 L->top--;
195 } 204 }
196 return name; 205 return name;
@@ -199,7 +208,7 @@ static const char *clib_extname(lua_State *L, const char *name)
199static void *clib_loadlib(lua_State *L, const char *name, int global) 208static void *clib_loadlib(lua_State *L, const char *name, int global)
200{ 209{
201 DWORD oldwerr = GetLastError(); 210 DWORD oldwerr = GetLastError();
202 void *h = (void *)LoadLibraryA(clib_extname(L, name)); 211 void *h = (void *)LoadLibraryExA(clib_extname(L, name), NULL, 0);
203 if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name); 212 if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name);
204 SetLastError(oldwerr); 213 SetLastError(oldwerr);
205 UNUSED(global); 214 UNUSED(global);
@@ -240,9 +249,9 @@ static void *clib_getsym(CLibrary *cl, const char *name)
240 GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, 249 GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
241 (const char *)&_fmode, &h); 250 (const char *)&_fmode, &h);
242 break; 251 break;
243 case CLIB_HANDLE_KERNEL32: h = LoadLibraryA("kernel32.dll"); break; 252 case CLIB_HANDLE_KERNEL32: h = LoadLibraryExA("kernel32.dll", NULL, 0); break;
244 case CLIB_HANDLE_USER32: h = LoadLibraryA("user32.dll"); break; 253 case CLIB_HANDLE_USER32: h = LoadLibraryExA("user32.dll", NULL, 0); break;
245 case CLIB_HANDLE_GDI32: h = LoadLibraryA("gdi32.dll"); break; 254 case CLIB_HANDLE_GDI32: h = LoadLibraryExA("gdi32.dll", NULL, 0); break;
246 } 255 }
247 if (!h) continue; 256 if (!h) continue;
248 clib_def_handle[i] = (void *)h; 257 clib_def_handle[i] = (void *)h;
@@ -263,7 +272,7 @@ static void *clib_getsym(CLibrary *cl, const char *name)
263LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt, 272LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,
264 const char *name) 273 const char *name)
265{ 274{
266 lj_err_callermsg(L, lj_str_pushf(L, fmt, name, "no support for this OS")); 275 lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, "no support for this OS"));
267} 276}
268 277
269static void *clib_loadlib(lua_State *L, const char *name, int global) 278static void *clib_loadlib(lua_State *L, const char *name, int global)
@@ -347,7 +356,7 @@ TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name)
347 CTInfo cconv = ctype_cconv(ct->info); 356 CTInfo cconv = ctype_cconv(ct->info);
348 if (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) { 357 if (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) {
349 CTSize sz = clib_func_argsize(cts, ct); 358 CTSize sz = clib_func_argsize(cts, ct);
350 const char *symd = lj_str_pushf(L, 359 const char *symd = lj_strfmt_pushf(L,
351 cconv == CTCC_FASTCALL ? "@%s@%d" : "_%s@%d", 360 cconv == CTCC_FASTCALL ? "@%s@%d" : "_%s@%d",
352 sym, sz); 361 sym, sz);
353 L->top--; 362 L->top--;