Skip to content
Permalink
Browse files
Fixed support of UTF-8 root path suppport LUA on Windows
With this patch is no matter where PGE is placed, "require()" function will work in any case.
  • Loading branch information
Wohlstand committed Mar 22, 2016
1 parent 6d28d24 commit b1c6a9dff634325724e707b155d0c515b3abe7f5
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 44 deletions.
@@ -37,7 +37,7 @@
#endif
#define LUA_LROOT "/usr/local"
#define LUA_LUADIR "/lua/5.1/"
#define LUA_LJDIR "/luajit-2.0.3/"
#define LUA_LJDIR "/luajit-2.0.4/"

#ifdef LUA_ROOT
#define LUA_JROOT LUA_ROOT
@@ -30,9 +30,9 @@

#include "lua.h"

#define LUAJIT_VERSION "LuaJIT 2.0.3"
#define LUAJIT_VERSION_NUM 20003 /* Version 2.0.3 = 02.00.03. */
#define LUAJIT_VERSION_SYM luaJIT_version_2_0_3
#define LUAJIT_VERSION "LuaJIT 2.0.4"
#define LUAJIT_VERSION_NUM 20004 /* Version 2.0.4 = 02.00.04. */
#define LUAJIT_VERSION_SYM luaJIT_version_2_0_4
#define LUAJIT_COPYRIGHT "Copyright (C) 2005-2015 Mike Pall"
#define LUAJIT_URL "http://luajit.org/"

Binary file not shown.
@@ -1,11 +1,11 @@
# Package information for LuaJIT to be used by pkg-config.
majver=2
minver=0
relver=3
relver=4
version=${majver}.${minver}.${relver}
abiver=5.1

prefix=D:/Developer/__GitHubRepos/PGE-Project/_Libs/_builds/win32/
prefix=C:/_Repos/PGE-Project/_Libs/_builds/win32/
multilib=lib
exec_prefix=${prefix}
libdir=${exec_prefix}/${multilib}
@@ -41,7 +41,7 @@

-- Cache some library functions and objects.
local jit = require("jit")
assert(jit.version_num == 20003, "LuaJIT core/library version mismatch")
assert(jit.version_num == 20004, "LuaJIT core/library version mismatch")
local jutil = require("jit.util")
local vmdef = require("jit.vmdef")
local bit = require("bit")
@@ -11,7 +11,7 @@
------------------------------------------------------------------------------

local jit = require("jit")
assert(jit.version_num == 20003, "LuaJIT core/library version mismatch")
assert(jit.version_num == 20004, "LuaJIT core/library version mismatch")
local bit = require("bit")

-- Symbol name prefix for LuaJIT bytecode.
@@ -55,7 +55,7 @@

-- Cache some library functions and objects.
local jit = require("jit")
assert(jit.version_num == 20003, "LuaJIT core/library version mismatch")
assert(jit.version_num == 20004, "LuaJIT core/library version mismatch")
local jutil = require("jit.util")
local vmdef = require("jit.vmdef")
local funcinfo, funcbc = jutil.funcinfo, jutil.funcbc
@@ -564,6 +564,7 @@ local function dump_trace(what, tr, func, pc, otr, oex)
end
if dumpmode.H then out:write("</pre>\n\n") else out:write("\n") end
else
if what == "flush" then symtab, nexitsym = {}, 0 end
out:write("---- TRACE ", what, "\n\n")
end
out:flush()
@@ -59,7 +59,7 @@

-- Cache some library functions and objects.
local jit = require("jit")
assert(jit.version_num == 20003, "LuaJIT core/library version mismatch")
assert(jit.version_num == 20004, "LuaJIT core/library version mismatch")
local jutil = require("jit.util")
local vmdef = require("jit.vmdef")
local funcinfo, traceinfo = jutil.funcinfo, jutil.traceinfo
@@ -99,7 +99,7 @@ traceerr = {
"JIT compilation disabled for function",
"call unroll limit reached",
"down-recursion, restarting",
"NYI: C function %p",
"NYI: C function %s",
"NYI: FastFunc %s",
"NYI: unsupported variant of FastFunc %s",
"NYI: return to lower frame",
Binary file not shown.
@@ -71,7 +71,8 @@ SOURCES += ../lua/lapi.c \
../src/set_package_preload.cpp \
../src/stack_content_by_name.cpp \
../src/weak_ref.cpp \
../src/wrapper_base.cpp
../src/wrapper_base.cpp \
../lua/file_open.c

HEADERS += ../lua/lapi.h \
../lua/lauxlib.h \
@@ -193,5 +194,6 @@ HEADERS += ../lua/lapi.h \
../luabind/weak_ref.hpp \
../luabind/wrapper_base.hpp \
../luabind/yield_policy.hpp \
../lua_inclues/lua.hpp
../lua_inclues/lua.hpp \
../lua/file_open.h

@@ -5,49 +5,36 @@
#ifdef _WIN32
#include <windows.h>

static size_t utf8len(const char *s)
{
size_t len = 0;
while(*s)
len += (*(s++)&0xC0)!=0x80;
return len;
}

FILE *_lua_fopen(const char *filename, const char *mode)
{
int fn_len=utf8len(filename);
int fn_len_s=strlen(filename);
if(fn_len==0) return NULL;

int m_len=utf8len(mode);
if(fn_len_s==0) return NULL;
int m_len_s=strlen(mode);
if(m_len==0) return NULL;

wchar_t *path = (wchar_t*) LocalAlloc(LMEM_ZEROINIT, sizeof(wchar_t) * fn_len_s);
wchar_t *wmode = (wchar_t*) LocalAlloc(LMEM_ZEROINIT, sizeof(wchar_t) *m_len_s);
MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
if(m_len_s==0) return NULL;
wchar_t path[MAX_PATH];
wchar_t wmode[MAX_PATH];
int new_Len1 = MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
if(new_Len1>=MAX_PATH) return NULL;
path[new_Len1] = L'\0';
int new_Len2 = MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
if(new_Len2>=MAX_PATH) return NULL;
wmode[new_Len2] = L'\0';
FILE *f = _wfopen(path, wmode);
LocalFree(path);
LocalFree(wmode);
return f;
}

FILE *_lua_freopen(const char *filename, const char *mode, FILE * oldfile)
{
int fn_len=utf8len(filename);
int fn_len_s=strlen(filename);
if(fn_len==0) return NULL;

int m_len=utf8len(filename);
if(fn_len_s==0) return NULL;
int m_len_s=strlen(filename);
if(m_len==0) return NULL;

wchar_t *path = (wchar_t*) LocalAlloc(LMEM_ZEROINIT, sizeof(wchar_t) * fn_len_s);
wchar_t *wmode = (wchar_t*) LocalAlloc(LMEM_ZEROINIT, sizeof(wchar_t) *m_len_s);

MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
if(m_len_s==0) return NULL;
wchar_t path[MAX_PATH];
wchar_t wmode[MAX_PATH];
int new_Len1 = MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
path[new_Len1] = L'\0';
int new_Len2 = MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
wmode[new_Len2] = L'\0';
FILE *f = _wfreopen(path, wmode, oldfile);
LocalFree(path);
LocalFree(wmode);

0 comments on commit b1c6a9d

Please sign in to comment.