beta-0.89.2
[luatex.git] / source / libs / luajit / LuaJIT-PATCHES / patch-01-LuaJITTeX
blob4853f00cc52bfcc0299f021b23aede744eb3a793
1 diff -ur LuaJIT-2.1.0-beta1.orig/src/lauxlib.h LuaJIT-2.1.0-beta1/src/lauxlib.h
2 --- LuaJIT-2.1.0-beta1.orig/src/lauxlib.h       2015-08-25 23:35:00.000000000 +0200
3 +++ LuaJIT-2.1.0-beta1/src/lauxlib.h    2015-09-04 08:42:39.000000000 +0200
4 @@ -86,6 +86,32 @@
5                                 int level);
6  
7  
9 +/*
10 +** {======================================================
11 +** File handles for IO library
12 +** =======================================================
13 +*/
15 +/*
16 +** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
17 +** initial structure 'luaL_Stream' (it may contain other fields
18 +** after that initial structure).
19 +*/
21 +#define LUA_FILEHANDLE          "FILE*"
24 +typedef struct luaL_Stream {
25 +  FILE *f;  /* stream (NULL for incompletely created streams) */
26 +  lua_CFunction closef;  /* to close stream (NULL for closed streams) */
27 +} luaL_Stream;
29 +/* }====================================================== */
34  /*
35  ** ===============================================================
36  ** some useful macros
37 diff -ur LuaJIT-2.1.0-beta1.orig/src/lib_init.c LuaJIT-2.1.0-beta1/src/lib_init.c
38 --- LuaJIT-2.1.0-beta1.orig/src/lib_init.c      2015-08-25 23:35:00.000000000 +0200
39 +++ LuaJIT-2.1.0-beta1/src/lib_init.c   2015-09-04 08:42:39.000000000 +0200
40 @@ -26,6 +26,7 @@
41    { LUA_DBLIBNAME,     luaopen_debug },
42    { LUA_BITLIBNAME,    luaopen_bit },
43    { LUA_JITLIBNAME,    luaopen_jit },
44 +  { LUA_BITLIBNAME_32, luaopen_bit32 },
45    { NULL,              NULL }
46  };
48 diff -ur LuaJIT-2.1.0-beta1.orig/src/lib_package.c LuaJIT-2.1.0-beta1/src/lib_package.c
49 --- LuaJIT-2.1.0-beta1.orig/src/lib_package.c   2015-08-25 23:35:00.000000000 +0200
50 +++ LuaJIT-2.1.0-beta1/src/lib_package.c        2015-09-04 08:42:39.000000000 +0200
51 @@ -362,6 +362,29 @@
52    return 1;  /* library loaded successfully */
53  }
55 +#define LUA_POF                "luaopen_"
56 +#define LUA_OFSEP      "_"
57 +#define POF            LUA_POF
59 +static const char *mkfuncname (lua_State *L, const char *modname) {
60 +  const char *funcname;
61 +  const char *mark = strchr(modname, *LUA_IGMARK);
62 +  if (mark) modname = mark + 1;
63 +  funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
64 +  funcname = lua_pushfstring(L, POF"%s", funcname);
65 +  lua_remove(L, -2);  /* remove 'gsub' result */
66 +  return funcname;
70 +int loader_C_luatex (lua_State *L, const char *name, const char *filename) {
71 +  const char *funcname;
72 +  funcname = mkfuncname(L, name);
73 +  if (ll_loadfunc(L, filename, funcname,0) != 0)
74 +    loaderror(L, filename);
75 +  return 1;  /* library loaded successfully */
78  static int lj_cf_package_loader_croot(lua_State *L)
79  {
80    const char *filename;
81 @@ -381,6 +404,21 @@
82    return 1;
83  }
85 +int loader_Call_luatex (lua_State *L, const char *name, const char *filename) {
86 +  const char *funcname;
87 +  int stat;
88 +  if (filename == NULL) return 1;  /* root not found */
89 +  funcname = mkfuncname(L, name);
90 +  if ((stat = ll_loadfunc(L, filename, funcname,0)) != 0) {
91 +    if (stat != PACKAGE_ERR_FUNC) loaderror(L, filename);  /* real error */
92 +    lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
93 +                       name, filename);
94 +    return 1;  /* function not found */
95 +  }
96 +  return 1;  /* library loaded successfully */
100  static int lj_cf_package_loader_preload(lua_State *L)
102    const char *name = luaL_checkstring(L, 1);
103 diff -ur LuaJIT-2.1.0-beta1.orig/src/lua.h LuaJIT-2.1.0-beta1/src/lua.h
104 --- LuaJIT-2.1.0-beta1.orig/src/lua.h   2015-08-25 23:35:00.000000000 +0200
105 +++ LuaJIT-2.1.0-beta1/src/lua.h        2015-09-04 08:42:39.000000000 +0200
106 @@ -348,6 +348,16 @@
107                        const char *chunkname, const char *mode);
110 +#define LUA_OPEQ 0
111 +#define LUA_OPLT 1
112 +#define LUA_OPLE 2
113 +#define LUA_OK  0
115 +/* see http://comments.gmane.org/gmane.comp.programming.swig/18673 */
116 +# define lua_rawlen lua_objlen 
120  struct lua_Debug {
121    int event;
122    const char *name;    /* (n) */
123 diff -ur LuaJIT-2.1.0-beta1.orig/src/lualib.h LuaJIT-2.1.0-beta1/src/lualib.h
124 --- LuaJIT-2.1.0-beta1.orig/src/lualib.h        2015-08-25 23:35:00.000000000 +0200
125 +++ LuaJIT-2.1.0-beta1/src/lualib.h     2015-09-04 08:42:39.000000000 +0200
126 @@ -22,6 +22,8 @@
127  #define LUA_JITLIBNAME "jit"
128  #define LUA_FFILIBNAME "ffi"
130 +#define LUA_BITLIBNAME_32  "bit32"
132  LUALIB_API int luaopen_base(lua_State *L);
133  LUALIB_API int luaopen_math(lua_State *L);
134  LUALIB_API int luaopen_string(lua_State *L);
135 @@ -34,6 +36,8 @@
136  LUALIB_API int luaopen_jit(lua_State *L);
137  LUALIB_API int luaopen_ffi(lua_State *L);
139 +LUALIB_API int luaopen_bit32(lua_State *L);
141  LUALIB_API void luaL_openlibs(lua_State *L);
143  #ifndef lua_assert
144 diff -ur LuaJIT-2.1.0-beta1.orig/src/Makefile LuaJIT-2.1.0-beta1/src/Makefile
145 --- LuaJIT-2.1.0-beta1.orig/src/Makefile        2015-08-25 23:35:00.000000000 +0200
146 +++ LuaJIT-2.1.0-beta1/src/Makefile     2015-09-04 08:42:39.000000000 +0200
147 @@ -97,7 +97,7 @@
148  # enabled by default. Some other features that *might* break some existing
149  # code (e.g. __pairs or os.execute() return values) can be enabled here.
150  # Note: this does not provide full compatibility with Lua 5.2 at this time.
151 -#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
152 +XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
154  # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
155  #XCFLAGS+= -DLUAJIT_DISABLE_JIT
156 @@ -456,7 +456,7 @@
157  LJVM_BOUT= $(LJVM_S)
158  LJVM_MODE= elfasm
160 -LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
161 +LJLIB_O= lib_base.o lib_math.o lbitlib.o lib_bit.o lib_string.o lib_table.o \
162          lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
163  LJLIB_C= $(LJLIB_O:.o=.c)
165 diff -ur LuaJIT-2.1.0-beta1.orig/src/Makefile.dep LuaJIT-2.1.0-beta1/src/Makefile.dep
166 --- LuaJIT-2.1.0-beta1.orig/src/Makefile.dep    2015-08-25 23:35:00.000000000 +0200
167 +++ LuaJIT-2.1.0-beta1/src/Makefile.dep 2015-09-04 08:46:10.000000000 +0200
168 @@ -6,6 +6,7 @@
169   lj_tab.h lj_meta.h lj_state.h lj_ctype.h lj_cconv.h lj_bc.h lj_ff.h \
170   lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \
171   lj_strfmt.h lj_lib.h lj_libdef.h
172 +lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
173  lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
174   lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_strscan.h \
175   lj_strfmt.h lj_ctype.h lj_cdata.h lj_cconv.h lj_carith.h lj_ff.h \