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

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstarkos <none@none>2009-01-13 02:41:05 +0300
committerstarkos <none@none>2009-01-13 02:41:05 +0300
commit0f9756378c93fcd869e312b1c4b251fd806a7645 (patch)
tree5531341c9863310839e0ba88eb33cb5069900be6 /src/host/lua-5.1.4
parent7e635f9685809fe8757dc1cab93e1f9af35100a5 (diff)
Patched Lua to load precompiled bytecodes on PPC architecture
Diffstat (limited to 'src/host/lua-5.1.4')
-rw-r--r--src/host/lua-5.1.4/src/lundump.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/host/lua-5.1.4/src/lundump.c b/src/host/lua-5.1.4/src/lundump.c
index 8010a45..9a43f7c 100644
--- a/src/host/lua-5.1.4/src/lundump.c
+++ b/src/host/lua-5.1.4/src/lundump.c
@@ -4,6 +4,9 @@
** See Copyright Notice in lua.h
*/
+/* jperkins: applied endian-independence patch to enable Premake's precompiled scripts
+ * to be shipped in a universal binary. See http://lua-users.org/lists/lua-l/2006-02/msg00507.html */
+
#include <string.h>
#define lundump_c
@@ -25,6 +28,7 @@ typedef struct {
ZIO* Z;
Mbuffer* b;
const char* name;
+ int swap;
} LoadState;
#ifdef LUAC_TRUST_BINARIES
@@ -40,7 +44,7 @@ static void error(LoadState* S, const char* why)
}
#endif
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
+/* #define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) */
#define LoadByte(S) (lu_byte)LoadChar(S)
#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
@@ -51,6 +55,50 @@ static void LoadBlock(LoadState* S, void* b, size_t size)
IF (r!=0, "unexpected end");
}
+static void LoadMem (LoadState* S, void* b, int n, size_t size)
+{
+ LoadBlock(S,b,n*size);
+ if (S->swap)
+ {
+ char* p=(char*) b;
+ char c;
+ switch (size)
+ {
+ case 1:
+ break;
+ case 2:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[1]; p[1]=c;
+ p+=2;
+ }
+ break;
+ case 4:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[3]; p[3]=c;
+ c=p[1]; p[1]=p[2]; p[2]=c;
+ p+=4;
+ }
+ break;
+ case 8:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[7]; p[7]=c;
+ c=p[1]; p[1]=p[6]; p[6]=c;
+ c=p[2]; p[2]=p[5]; p[5]=c;
+ c=p[3]; p[3]=p[4]; p[4]=c;
+ p+=8;
+ }
+ break;
+ default:
+ error(S,"bad size");
+ break;
+ }
+ }
+}
+
+
static int LoadChar(LoadState* S)
{
char x;
@@ -186,6 +234,7 @@ static void LoadHeader(LoadState* S)
char s[LUAC_HEADERSIZE];
luaU_header(h);
LoadBlock(S,s,LUAC_HEADERSIZE);
+ S->swap=(s[6]!=h[6]); s[6]=h[6];
IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
}