summaryrefslogtreecommitdiff
path: root/Build/source/libs/luajit/TLpatches/patch-01-LuaJITTeX
blob: 2e8220e0c36da3ff94588671c389faec82e65fdc (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
diff -bur LuaJIT-src-orig/src/lauxlib.h LuaJIT-src/src/lauxlib.h
--- LuaJIT-src-orig/src/lauxlib.h	2016-03-07 09:43:42.708069718 +0100
+++ LuaJIT-src/src/lauxlib.h	2016-03-04 16:52:23.000000000 +0100
@@ -86,6 +86,32 @@
 				int level);
 
 
+
+/*
+** {======================================================
+** File handles for IO library
+** =======================================================
+*/
+
+/*
+** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
+** initial structure 'luaL_Stream' (it may contain other fields
+** after that initial structure).
+*/
+
+#define LUA_FILEHANDLE          "FILE*"
+
+
+typedef struct luaL_Stream {
+  FILE *f;  /* stream (NULL for incompletely created streams) */
+  lua_CFunction closef;  /* to close stream (NULL for closed streams) */
+} luaL_Stream;
+
+/* }====================================================== */
+
+
+
+
 /*
 ** ===============================================================
 ** some useful macros
@@ -144,6 +170,8 @@
 LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
 LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
 
+/* Luajittex needs this one because it overloads loadfile */
+LUALIB_API int (RESERVED_load_aux_JIT) (lua_State *L, int status, int envarg);
 
 /* }====================================================== */
 
diff -bur LuaJIT-src-orig/src/lib_init.c LuaJIT-src/src/lib_init.c
--- LuaJIT-src-orig/src/lib_init.c	2016-03-07 09:43:42.720069718 +0100
+++ LuaJIT-src/src/lib_init.c	2016-03-07 11:47:15.847946480 +0100
@@ -26,6 +26,7 @@
   { LUA_DBLIBNAME,	luaopen_debug },
   { LUA_BITLIBNAME,	luaopen_bit },
   { LUA_JITLIBNAME,	luaopen_jit },
+  { LUA_BITLIBNAME_32,	luaopen_bit32 },
   { NULL,		NULL }
 };
 
diff -bur LuaJIT-src-orig/src/lib_package.c LuaJIT-src/src/lib_package.c
--- LuaJIT-src-orig/src/lib_package.c	2016-03-07 09:43:42.712069718 +0100
+++ LuaJIT-src/src/lib_package.c	2016-03-07 11:49:15.655944489 +0100
@@ -362,6 +362,29 @@
   return 1;  /* library loaded successfully */
 }
 
+#define LUA_POF		"luaopen_"
+#define LUA_OFSEP	"_"
+#define POF		LUA_POF
+
+static const char *mkfuncname (lua_State *L, const char *modname) {
+  const char *funcname;
+  const char *mark = strchr(modname, *LUA_IGMARK);
+  if (mark) modname = mark + 1;
+  funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
+  funcname = lua_pushfstring(L, POF"%s", funcname);
+  lua_remove(L, -2);  /* remove 'gsub' result */
+  return funcname;
+}
+
+
+int loader_C_luatex (lua_State *L, const char *name, const char *filename) {
+  const char *funcname;
+  funcname = mkfuncname(L, name);
+  if (ll_loadfunc(L, filename, funcname,0) != 0)
+    loaderror(L, filename);
+  return 1;  /* library loaded successfully */
+}
+
 static int lj_cf_package_loader_croot(lua_State *L)
 {
   const char *filename;
@@ -381,6 +404,21 @@
   return 1;
 }
 
+int loader_Call_luatex (lua_State *L, const char *name, const char *filename) {
+  const char *funcname;
+  int stat;
+  if (filename == NULL) return 1;  /* root not found */
+  funcname = mkfuncname(L, name);
+  if ((stat = ll_loadfunc(L, filename, funcname,0)) != 0) {
+    if (stat != PACKAGE_ERR_FUNC) loaderror(L, filename);  /* real error */
+    lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
+                       name, filename);
+    return 1;  /* function not found */
+  }
+  return 1;  /* library loaded successfully */
+}
+
+
 static int lj_cf_package_loader_preload(lua_State *L)
 {
   const char *name = luaL_checkstring(L, 1);

diff -bur LuaJIT-src-orig/src/lj_load.c LuaJIT-src/src/lj_load.c
--- LuaJIT-src-orig/src/lj_load.c	2016-03-07 09:43:42.716069718 +0100
+++ LuaJIT-src/src/lj_load.c	2016-03-07 12:09:10.771924621 +0100
@@ -166,3 +166,19 @@
     return 1;
 }
 
+/* -- Luajittex needs this one because it overloads loadfile  -- */
+LUALIB_API int RESERVED_load_aux_JIT(lua_State *L, int status, int envarg)
+{
+  if (status == 0) {
+    if (tvistab(L->base+envarg-1)) {
+      GCfunc *fn = funcV(L->top-1);
+      GCtab *t = tabV(L->base+envarg-1);
+      setgcref(fn->c.env, obj2gco(t));
+      lj_gc_objbarrier(L, fn, t);
+    }
+    return 1;
+  } else {
+    setnilV(L->top-2);
+    return 2;
+  }
+}

diff -bur LuaJIT-src-orig/src/lua.h LuaJIT-src/src/lua.h
--- LuaJIT-src-orig/src/lua.h	2016-03-07 09:43:42.716069718 +0100
+++ LuaJIT-src/src/lua.h	2016-03-07 11:56:24.855937353 +0100
@@ -103,6 +103,9 @@
 typedef LUA_INTEGER lua_Integer;
 
 
+/* communication with LuaJiTTeX */
+LUA_API int luajittex_choose_hash_function; 
+
 
 /*
 ** state manipulation
@@ -349,6 +352,16 @@
 		       const char *chunkname, const char *mode);
 
 
+#define LUA_OPEQ 0
+#define LUA_OPLT 1
+#define LUA_OPLE 2
+#define LUA_OK  0
+
+/* see http://comments.gmane.org/gmane.comp.programming.swig/18673 */
+# define lua_rawlen lua_objlen 
+
+
+
 struct lua_Debug {
   int event;
   const char *name;	/* (n) */

diff -bur LuaJIT-src-orig/src/lualib.h LuaJIT-src/src/lualib.h
--- LuaJIT-src-orig/src/lualib.h	2016-03-07 09:43:42.724069718 +0100
+++ LuaJIT-src/src/lualib.h	2016-03-07 11:58:19.151935453 +0100
@@ -22,6 +22,8 @@
 #define LUA_JITLIBNAME	"jit"
 #define LUA_FFILIBNAME	"ffi"
 
+#define LUA_BITLIBNAME_32  "bit32"
+
 LUALIB_API int luaopen_base(lua_State *L);
 LUALIB_API int luaopen_math(lua_State *L);
 LUALIB_API int luaopen_string(lua_State *L);
@@ -34,6 +36,8 @@
 LUALIB_API int luaopen_jit(lua_State *L);
 LUALIB_API int luaopen_ffi(lua_State *L);
 
+LUALIB_API int luaopen_bit32(lua_State *L);
+
 LUALIB_API void luaL_openlibs(lua_State *L);
 
 #ifndef lua_assert

diff -bur LuaJIT-src-orig/src/Makefile LuaJIT-src/src/Makefile
--- LuaJIT-src-orig/src/Makefile	2016-03-07 09:43:42.716069718 +0100
+++ LuaJIT-src/src/Makefile	2016-03-07 12:02:42.319931078 +0100
@@ -99,7 +99,7 @@
 # enabled by default. Some other features that *might* break some existing
 # code (e.g. __pairs or os.execute() return values) can be enabled here.
 # Note: this does not provide full compatibility with Lua 5.2 at this time.
-#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
+XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
 #
 # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
 #XCFLAGS+= -DLUAJIT_DISABLE_JIT
@@ -471,7 +471,7 @@
 LJVM_BOUT= $(LJVM_S)
 LJVM_MODE= elfasm
 
-LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
+LJLIB_O= lib_base.o lib_math.o lbitlib.o lib_bit.o lib_string.o lib_table.o \
 	 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
 LJLIB_C= $(LJLIB_O:.o=.c)
 
diff -bur LuaJIT-src-orig/src/Makefile.dep LuaJIT-src/src/Makefile.dep
--- LuaJIT-src-orig/src/Makefile.dep	2016-03-07 09:43:42.696069718 +0100
+++ LuaJIT-src/src/Makefile.dep	2016-03-07 12:05:19.343928468 +0100
@@ -6,6 +6,7 @@
  lj_tab.h lj_meta.h lj_state.h lj_ctype.h lj_cconv.h lj_bc.h lj_ff.h \
  lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \
  lj_strfmt.h lj_lib.h lj_libdef.h
+lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
 lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
  lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_strscan.h \
  lj_strfmt.h lj_ctype.h lj_cdata.h lj_cconv.h lj_carith.h lj_ff.h \