lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello!

I would like to contribute a patch to the original lua sources, which facilitate compilation under Microsoft compilers. lua51_wince.patch applies to a clean lua-5.1.4\src directory and
lua52_wince.patch to a clean lua-5.2.0-beta\src directory.

In some Windows API function calls just an "A" was appended to the name to force the use of
the ANSI version instead of the UNICODE version of the function.

luaconf.h adds support for Windows Mobile/Windows CE compilers (_WIN32_WCE) by excluding some
features (like popen).

LUAI_FUNC and LUAI_DATA/LUAI_DDEC are declared for proper export with _delcspec(dllexport) under _MSC_VER just like already done for LUA_API and LUALIB_API. I needed this for luac.exe.

The LoadString() function in lundump.c conflicts with the WindowsAPI LoadString() function.
The patches handle this situation only under _WIN32_WCE.

- - -

Is this the usual way to get changes eventually into the lua sources?

Best Regards,

    Jorge-León

--- liolib.c	Thu Jan 15 10:14:12 1970
+++ liolib.c	Thu Jan 15 10:14:12 1970
@@ -31,7 +31,7 @@
 #define lua_popen(L,c,m)	((void)L, fflush(NULL), popen(c,m))
 #define lua_pclose(L,file)	((void)L, pclose(file))
 
-#elif defined(LUA_WIN)		/* }{ */
+#elif defined(LUA_WIN) && !defined(_WIN32_WCE)	/* }{ */
 
 #define lua_popen(L,c,m)		((void)L, _popen(c,m))
 #define lua_pclose(L,file)		((void)L, _pclose(file))
--- loadlib.c	Thu Jan 15 10:14:12 1970
+++ loadlib.c	Thu Jan 15 10:14:12 1970
@@ -184,7 +184,7 @@
 
 
 static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
-  lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);
+  lua_CFunction f = (lua_CFunction)GetProcAddressA((HMODULE)lib, sym);
   if (f == NULL) pusherror(L);
   return f;
 }
--- lua.c	Thu Jan 15 10:14:12 1970
+++ lua.c	Thu Jan 15 10:14:12 1970
@@ -46,7 +46,7 @@
 #if defined(LUA_USE_ISATTY)
 #include <unistd.h>
 #define lua_stdin_is_tty()      isatty(0)
-#elif defined(LUA_WIN)
+#elif defined(LUA_WIN) && !defined(_WIN32_WCE)
 #include <io.h>
 #include <stdio.h>
 #define lua_stdin_is_tty()      _isatty(_fileno(stdin))
--- luaconf.h	Thu Jan 15 10:14:12 1970
+++ luaconf.h	Thu Jan 15 10:14:12 1970
@@ -58,7 +58,19 @@
 #define LUA_USE_LONGLONG	/* assume support for long long */
 #endif
 
+#if defined(_WIN32_WCE)
 
+#include <wince.h>
+
+#if defined(luac_c)
+#undef VOID
+#endif
+/* used in lundump.c */
+#if defined(lundump_c)
+#undef LoadString
+#endif
+
+#endif
 
 /*
 @@ LUA_USE_POSIX includes all functionality listed as X/Open System
@@ -88,17 +100,24 @@
 ** In Windows, any exclamation mark ('!') in the path is replaced by the
 ** path of the directory of the executable file of the current process.
 */
+#ifndef _WIN32_WCE
 #define LUA_LDIR	"!\\lua\\"
 #define LUA_CDIR	"!\\"
 #define LUA_PATH_DEFAULT  \
 		LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
 		LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua;" ".\\?.lua"
 #define LUA_CPATH_DEFAULT \
-		LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
-
-#else			/* }{ */
-
-#define LUA_VDIR	LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
+	".\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
+#else
+#define LUA_LDIR	"!\\lua\\"
+#define LUA_CDIR	"!\\"
+#define LUA_PATH_DEFAULT  \
+		"\\Windows\\?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
+		             LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
+#define LUA_CPATH_DEFAULT \
+	"\\Windows\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
+#endif
+#else
 #define LUA_ROOT	"/usr/local/"
 #define LUA_LDIR	LUA_ROOT "share/lua/" LUA_VDIR
 #define LUA_CDIR	LUA_ROOT "lib/lua/" LUA_VDIR
@@ -183,6 +202,15 @@
 #define LUAI_FUNC	__attribute__((visibility("hidden"))) extern
 #define LUAI_DDEC	LUAI_FUNC
 #define LUAI_DDEF	/* empty */
+
+#elif defined(_MSC_VER)
+#if defined(LUA_BUILD_AS_DLL)
+#define LUAI_FUNC  __declspec(dllexport)
+#else
+#define LUAI_FUNC extern
+#endif
+#define LUAI_DDEC  LUAI_FUNC
+#define LUAI_DDEF  /* empty */
 
 #else				/* }{ */
 #define LUAI_FUNC	extern
--- loadlib.c	Thu Jan 15 10:14:12 1970
+++ loadlib.c	Thu Jan 15 10:14:12 1970
@@ -132,7 +132,7 @@
 
 
 static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
-  lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);
+  lua_CFunction f = (lua_CFunction)GetProcAddressA((HINSTANCE)lib, sym);
   if (f == NULL) pusherror(L);
   return f;
 }
--- luaconf.h	Thu Jan 15 10:14:12 1970
+++ luaconf.h	Thu Jan 15 10:14:12 1970
@@ -44,7 +44,20 @@
 #define LUA_DL_DYLD		/* does not need extra library */
 #endif
 
+#if defined(_WIN32_WCE)
 
+#include "..\wince\wince.h"
+
+/* used in print.c */
+#if defined(luac_c)
+#undef VOID
+#endif
+/* used in lundump.c */
+#if defined(lundump_c)
+#undef LoadString
+#endif
+
+#endif
 
 /*
 @@ LUA_USE_POSIX includes all functionallity listed as X/Open System
@@ -85,6 +98,7 @@
 ** In Windows, any exclamation mark ('!') in the path is replaced by the
 ** path of the directory of the executable file of the current process.
 */
+#ifndef _WIN32_WCE
 #define LUA_LDIR	"!\\lua\\"
 #define LUA_CDIR	"!\\"
 #define LUA_PATH_DEFAULT  \
@@ -92,7 +106,15 @@
 		             LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
 #define LUA_CPATH_DEFAULT \
 	".\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
-
+#else
+#define LUA_LDIR	"!\\lua\\"
+#define LUA_CDIR	"!\\"
+#define LUA_PATH_DEFAULT  \
+		"\\Windows\\?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
+		             LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
+#define LUA_CPATH_DEFAULT \
+	"\\Windows\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
+#endif
 #else
 #define LUA_ROOT	"/usr/local/"
 #define LUA_LDIR	LUA_ROOT "share/lua/5.1/"
@@ -187,6 +209,13 @@
 #define LUAI_FUNC	__attribute__((visibility("hidden"))) extern
 #define LUAI_DATA	LUAI_FUNC
 
+#elif defined(_MSC_VER)
+#if defined(LUA_BUILD_AS_DLL)
+#define LUAI_FUNC  __declspec(dllexport)
+#else
+#define LUAI_FUNC  extern
+#endif
+#define LUAI_DATA  /* empty */
 #else
 #define LUAI_FUNC	extern
 #define LUAI_DATA	extern
@@ -227,7 +256,7 @@
 #if defined(LUA_USE_ISATTY)
 #include <unistd.h>
 #define lua_stdin_is_tty()	isatty(0)
-#elif defined(LUA_WIN)
+#elif defined(LUA_WIN) && !defined(_WIN32_WCE)
 #include <io.h>
 #include <stdio.h>
 #define lua_stdin_is_tty()	_isatty(_fileno(stdin))
@@ -670,7 +699,7 @@
 #define lua_popen(L,c,m)	((void)L, fflush(NULL), popen(c,m))
 #define lua_pclose(L,file)	((void)L, (pclose(file) != -1))
 
-#elif defined(LUA_WIN)
+#elif defined(LUA_WIN) && !defined(_WIN32_WCE)
 
 #define lua_popen(L,c,m)	((void)L, _popen(c,m))
 #define lua_pclose(L,file)	((void)L, (_pclose(file) != -1))