Skip to content

Commit 75a4659

Browse files
author
Bin Zhang
authored
Merge pull request #376 from dumganhar/re-update-luajit
Updates luajit to 2.1.0-beta2 for luacompile binary, luacompile supports to generate 64bit luajit bytecode
2 parents 2ebad9a + 8a2e185 commit 75a4659

40 files changed

+5820
-227
lines changed

bin/strings.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@
105105
"LUACOMPILE_ARG_ENCRYPT" : "Whether or not to encrypt.",
106106
"LUACOMPILE_ARG_ENCRYPT_KEY" : "The key for encrypt.",
107107
"LUACOMPILE_ARG_ENCRYPT_SIGN" : "The sign for encrypt.",
108-
"LUACOMPILE_ARG_DISABLE_COMPILE" : "Not compile the lua files to bytecode.",
108+
"LUACOMPILE_ARG_DISABLE_COMPILE" : "Don't compile the lua files to bytecode.",
109+
"LUACOMPILE_ARG_BYTECODE_64BIT": "Generate 64bit luajit bytecode",
109110
"LUACOMPILE_DEBUG_COMPILE_FILE_FMT" : "Compiling lua (%s) to bytecode...",
110111
"LUACOMPILE_INFO_PROCESS_FILE" : "Processing lua script files",
111-
"LUACOMPILE_WARNING_TIP_MSG" : "By using luacompile, you could precompile the Lua script files to the bytecode files and encrypt the Lua script files or the bytecode files by XXTEA.\nThe mechanism of generating the bytecode files is based on the LuaJIT v2.0.3, so the generated bytecode files cann't be used on the 64-bit iOS devices.",
112+
"LUACOMPILE_WARNING_TIP_MSG" : "By using luacompile, you could precompile the Lua script files to the bytecode files and encrypt the Lua script files or the bytecode files by XXTEA.",
112113
"LUACOMPILE_INFO_FINISHED" : "Compilation finished.",
113114
"LUACOMPILE_ERROR_TOOL_NOT_FOUND" : "Can't find right luajit for current system.",
114115
"LUACOMPILE_ERROR_SRCDIR_NAME_NOT_FOUND" : "Can't find src directory in file path.",
@@ -434,9 +435,10 @@
434435
"LUACOMPILE_ARG_ENCRYPT_KEY" : "指定 XXTEA 加密功能的 key 字段。",
435436
"LUACOMPILE_ARG_ENCRYPT_SIGN" : "指定 XXTEA 加密功能的 sign 字段。",
436437
"LUACOMPILE_ARG_DISABLE_COMPILE" : "关闭编译为字节码的功能。",
438+
"LUACOMPILE_ARG_BYTECODE_64BIT": "生成64位Luajit格式的字节码",
437439
"LUACOMPILE_DEBUG_COMPILE_FILE_FMT" : "正在将 %s 编译为字节码...",
438440
"LUACOMPILE_INFO_PROCESS_FILE" : "正在处理 lua 文件。",
439-
"LUACOMPILE_WARNING_TIP_MSG" : "通过 luacompile 命令对 lua 文件进行 XXTEA 加密以及编译为字节码的处理。\n编译为字节码的功能基于 LuaJIT v2.0.3,所以目前编译成字节码的文件不适用于 iOS 64位设备。",
441+
"LUACOMPILE_WARNING_TIP_MSG" : "通过 luacompile 命令对 lua 文件进行 XXTEA 加密以及编译为字节码的处理。",
440442
"LUACOMPILE_INFO_FINISHED" : "编译完成。",
441443
"LUACOMPILE_ERROR_TOOL_NOT_FOUND" : "无法找到适用于当前系统的 luajit。",
442444
"LUACOMPILE_ERROR_SRCDIR_NAME_NOT_FOUND" : "在文件路径中找不到源目录。",
@@ -761,9 +763,10 @@
761763
"LUACOMPILE_ARG_ENCRYPT_KEY" : "指定 XXTEA 加密功能的 key 字段。",
762764
"LUACOMPILE_ARG_ENCRYPT_SIGN" : "指定 XXTEA 加密功能的 sign 字段。",
763765
"LUACOMPILE_ARG_DISABLE_COMPILE" : "關閉編譯為位元組碼的功能。",
766+
"LUACOMPILE_ARG_BYTECODE_64BIT": "生成64位Luajit格式的字節碼",
764767
"LUACOMPILE_DEBUG_COMPILE_FILE_FMT" : "正在將 %s 編譯為位元組碼...",
765768
"LUACOMPILE_INFO_PROCESS_FILE" : "正在處理 lua 檔案。",
766-
"LUACOMPILE_WARNING_TIP_MSG" : "通過 luacompile 命令對 lua 檔案進行 XXTEA 加密以及編譯為位元組碼的處理。\n編譯為位元組碼的功能基於 LuaJIT v2.0.3,所以目前編譯成位元組碼的檔案不適用於 iOS 64位設備。",
769+
"LUACOMPILE_WARNING_TIP_MSG" : "通過 luacompile 命令對 lua 檔案進行 XXTEA 加密以及編譯為位元組碼的處理。",
767770
"LUACOMPILE_INFO_FINISHED" : "編譯完成。",
768771
"LUACOMPILE_ERROR_TOOL_NOT_FOUND" : "無法找到適用於當前系統的 luajit。",
769772
"LUACOMPILE_ERROR_SRCDIR_NAME_NOT_FOUND" : "在檔案路徑中找不到原始目錄。",

plugins/plugin_luacompile/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def init(self, options, workingdir):
124124
self._isEncrypt = options.encrypt
125125
self._encryptkey = options.encryptkey
126126
self._encryptsign = options.encryptsign
127+
self._bytecode_64bit = options.bytecode_64bit
128+
127129
self._luajit_exe_path = self.get_luajit_path()
128130
self._disable_compile = options.disable_compile
129131

@@ -179,13 +181,16 @@ def get_output_file_path(self, luafile):
179181

180182
def get_luajit_path(self):
181183
ret = None
184+
185+
bit_prefix = "64bit" if self._bytecode_64bit else "32bit"
182186
if cocos.os_is_win32():
183-
ret = os.path.join(self._workingdir, "bin", "luajit.exe")
187+
ret = os.path.join(self._workingdir, "bin", bit_prefix, "luajit-win32.exe")
184188
elif cocos.os_is_mac():
185-
ret = os.path.join(self._workingdir, "bin", "lua", "luajit-mac")
189+
ret = os.path.join(self._workingdir, "bin", bit_prefix, "luajit-mac")
186190
elif cocos.os_is_linux():
187-
ret = os.path.join(self._workingdir, "bin", "lua", "luajit-linux")
191+
ret = os.path.join(self._workingdir, "bin", bit_prefix, "luajit-linux")
188192

193+
print("luajit bin path: " + ret)
189194
return ret
190195

191196
def compile_lua(self, lua_file, output_file):
@@ -299,6 +304,9 @@ def parse_args(self, argv):
299304
parser.add_argument("--disable-compile",
300305
action="store_true", dest="disable_compile", default=False,
301306
help=MultiLanguage.get_string('LUACOMPILE_ARG_DISABLE_COMPILE'))
307+
parser.add_argument("--bytecode-64bit",
308+
action="store_true", dest="bytecode_64bit", default=False,
309+
help=MultiLanguage.get_string('LUACOMPILE_ARG_BYTECODE_64BIT'))
302310

303311
options = parser.parse_args(argv)
304312

plugins/plugin_luacompile/bin/lua/jit/bc.lua renamed to plugins/plugin_luacompile/bin/32bit/jit/bc.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
----------------------------------------------------------------------------
22
-- LuaJIT bytecode listing module.
33
--
4-
-- Copyright (C) 2005-2013 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.
55
-- Released under the MIT license. See Copyright Notice in luajit.h
66
----------------------------------------------------------------------------
77
--
@@ -41,7 +41,7 @@
4141

4242
-- Cache some library functions and objects.
4343
local jit = require("jit")
44-
assert(jit.version_num == 20001, "LuaJIT core/library version mismatch")
44+
assert(jit.version_num == 20100, "LuaJIT core/library version mismatch")
4545
local jutil = require("jit.util")
4646
local vmdef = require("jit.vmdef")
4747
local bit = require("bit")
@@ -179,13 +179,12 @@ local function bcliston(outfile)
179179
end
180180

181181
-- Public module functions.
182-
module(...)
183-
184-
line = bcline
185-
dump = bcdump
186-
targets = bctargets
187-
188-
on = bcliston
189-
off = bclistoff
190-
start = bcliston -- For -j command line option.
182+
return {
183+
line = bcline,
184+
dump = bcdump,
185+
targets = bctargets,
186+
on = bcliston,
187+
off = bclistoff,
188+
start = bcliston -- For -j command line option.
189+
}
191190

plugins/plugin_luacompile/bin/lua/jit/bcsave.lua renamed to plugins/plugin_luacompile/bin/32bit/jit/bcsave.lua

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
----------------------------------------------------------------------------
22
-- LuaJIT module to save/list bytecode.
33
--
4-
-- Copyright (C) 2005-2013 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.
55
-- Released under the MIT license. See Copyright Notice in luajit.h
66
----------------------------------------------------------------------------
77
--
@@ -11,7 +11,7 @@
1111
------------------------------------------------------------------------------
1212

1313
local jit = require("jit")
14-
assert(jit.version_num == 20001, "LuaJIT core/library version mismatch")
14+
assert(jit.version_num == 20100, "LuaJIT core/library version mismatch")
1515
local bit = require("bit")
1616

1717
-- Symbol name prefix for LuaJIT bytecode.
@@ -63,13 +63,13 @@ local map_type = {
6363
}
6464

6565
local map_arch = {
66-
x86 = true, x64 = true, arm = true, ppc = true, ppcspe = true,
66+
x86 = true, x64 = true, arm = true, arm64 = true, ppc = true,
6767
mips = true, mipsel = true,
6868
}
6969

7070
local map_os = {
7171
linux = true, windows = true, osx = true, freebsd = true, netbsd = true,
72-
openbsd = true, solaris = true,
72+
openbsd = true, dragonfly = true, solaris = true,
7373
}
7474

7575
local function checkarg(str, map, err)
@@ -200,9 +200,9 @@ typedef struct {
200200
]]
201201
local symname = LJBC_PREFIX..ctx.modname
202202
local is64, isbe = false, false
203-
if ctx.arch == "x64" then
203+
if ctx.arch == "x64" or ctx.arch == "arm64" then
204204
is64 = true
205-
elseif ctx.arch == "ppc" or ctx.arch == "ppcspe" or ctx.arch == "mips" then
205+
elseif ctx.arch == "ppc" or ctx.arch == "mips" then
206206
isbe = true
207207
end
208208

@@ -237,7 +237,7 @@ typedef struct {
237237
hdr.eendian = isbe and 2 or 1
238238
hdr.eversion = 1
239239
hdr.type = f16(1)
240-
hdr.machine = f16(({ x86=3, x64=62, arm=40, ppc=20, ppcspe=20, mips=8, mipsel=8 })[ctx.arch])
240+
hdr.machine = f16(({ x86=3, x64=62, arm=40, arm64=183, ppc=20, mips=8, mipsel=8 })[ctx.arch])
241241
if ctx.arch == "mips" or ctx.arch == "mipsel" then
242242
hdr.flags = 0x50001006
243243
end
@@ -477,13 +477,13 @@ typedef struct {
477477
} mach_obj_64;
478478
typedef struct {
479479
mach_fat_header fat;
480-
mach_fat_arch fat_arch[4];
480+
mach_fat_arch fat_arch[2];
481481
struct {
482482
mach_header hdr;
483483
mach_segment_command seg;
484484
mach_section sec;
485485
mach_symtab_command sym;
486-
} arch[4];
486+
} arch[2];
487487
mach_nlist sym_entry;
488488
uint8_t space[4096];
489489
} mach_fat_obj;
@@ -494,6 +494,8 @@ typedef struct {
494494
is64, align, mobj = true, 8, "mach_obj_64"
495495
elseif ctx.arch == "arm" then
496496
isfat, mobj = true, "mach_fat_obj"
497+
elseif ctx.arch == "arm64" then
498+
is64, align, isfat, mobj = true, 8, true, "mach_fat_obj"
497499
else
498500
check(ctx.arch == "x86", "unsupported architecture for OSX")
499501
end
@@ -503,8 +505,8 @@ typedef struct {
503505
-- Create Mach-O object and fill in header.
504506
local o = ffi.new(mobj)
505507
local mach_size = aligned(ffi.offsetof(o, "space")+#symname+2, align)
506-
local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12,12,12} })[ctx.arch]
507-
local cpusubtype = ({ x86={3}, x64={3}, arm={3,6,9,11} })[ctx.arch]
508+
local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12}, arm64={0x01000007,0x0100000c} })[ctx.arch]
509+
local cpusubtype = ({ x86={3}, x64={3}, arm={3,9}, arm64={3,0} })[ctx.arch]
508510
if isfat then
509511
o.fat.magic = be32(0xcafebabe)
510512
o.fat.nfat_arch = be32(#cpusubtype)
@@ -653,7 +655,7 @@ end
653655
------------------------------------------------------------------------------
654656

655657
-- Public module functions.
656-
module(...)
657-
658-
start = docmd -- Process -b command line option.
658+
return {
659+
start = docmd -- Process -b command line option.
660+
}
659661

plugins/plugin_luacompile/bin/lua/jit/dis_arm.lua renamed to plugins/plugin_luacompile/bin/32bit/jit/dis_arm.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
----------------------------------------------------------------------------
22
-- LuaJIT ARM disassembler module.
33
--
4-
-- Copyright (C) 2005-2013 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.
55
-- Released under the MIT license. See Copyright Notice in luajit.h
66
----------------------------------------------------------------------------
77
-- This is a helper module used by the LuaJIT machine code dumper module.
@@ -658,7 +658,7 @@ local function disass_block(ctx, ofs, len)
658658
end
659659

660660
-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).
661-
local function create_(code, addr, out)
661+
local function create(code, addr, out)
662662
local ctx = {}
663663
ctx.code = code
664664
ctx.addr = addr or 0
@@ -670,20 +670,20 @@ local function create_(code, addr, out)
670670
end
671671

672672
-- Simple API: disassemble code (a string) at address and output via out.
673-
local function disass_(code, addr, out)
674-
create_(code, addr, out):disass()
673+
local function disass(code, addr, out)
674+
create(code, addr, out):disass()
675675
end
676676

677677
-- Return register name for RID.
678-
local function regname_(r)
678+
local function regname(r)
679679
if r < 16 then return map_gpr[r] end
680680
return "d"..(r-16)
681681
end
682682

683683
-- Public module functions.
684-
module(...)
685-
686-
create = create_
687-
disass = disass_
688-
regname = regname_
684+
return {
685+
create = create,
686+
disass = disass,
687+
regname = regname
688+
}
689689

plugins/plugin_luacompile/bin/lua/jit/dis_mips.lua renamed to plugins/plugin_luacompile/bin/32bit/jit/dis_mips.lua

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
----------------------------------------------------------------------------
22
-- LuaJIT MIPS disassembler module.
33
--
4-
-- Copyright (C) 2005-2013 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.
55
-- Released under the MIT/X license. See Copyright Notice in luajit.h
66
----------------------------------------------------------------------------
77
-- This is a helper module used by the LuaJIT machine code dumper module.
@@ -384,7 +384,7 @@ local function disass_block(ctx, ofs, len)
384384
end
385385

386386
-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).
387-
local function create_(code, addr, out)
387+
local function create(code, addr, out)
388388
local ctx = {}
389389
ctx.code = code
390390
ctx.addr = addr or 0
@@ -396,33 +396,33 @@ local function create_(code, addr, out)
396396
return ctx
397397
end
398398

399-
local function create_el_(code, addr, out)
400-
local ctx = create_(code, addr, out)
399+
local function create_el(code, addr, out)
400+
local ctx = create(code, addr, out)
401401
ctx.get = get_le
402402
return ctx
403403
end
404404

405405
-- Simple API: disassemble code (a string) at address and output via out.
406-
local function disass_(code, addr, out)
407-
create_(code, addr, out):disass()
406+
local function disass(code, addr, out)
407+
create(code, addr, out):disass()
408408
end
409409

410-
local function disass_el_(code, addr, out)
411-
create_el_(code, addr, out):disass()
410+
local function disass_el(code, addr, out)
411+
create_el(code, addr, out):disass()
412412
end
413413

414414
-- Return register name for RID.
415-
local function regname_(r)
415+
local function regname(r)
416416
if r < 32 then return map_gpr[r] end
417417
return "f"..(r-32)
418418
end
419419

420420
-- Public module functions.
421-
module(...)
422-
423-
create = create_
424-
create_el = create_el_
425-
disass = disass_
426-
disass_el = disass_el_
427-
regname = regname_
421+
return {
422+
create = create,
423+
create_el = create_el,
424+
disass = disass,
425+
disass_el = disass_el,
426+
regname = regname
427+
}
428428

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
----------------------------------------------------------------------------
22
-- LuaJIT MIPSEL disassembler wrapper module.
33
--
4-
-- Copyright (C) 2005-2013 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.
55
-- Released under the MIT license. See Copyright Notice in luajit.h
66
----------------------------------------------------------------------------
77
-- This module just exports the little-endian functions from the
88
-- MIPS disassembler module. All the interesting stuff is there.
99
------------------------------------------------------------------------------
1010

11-
local require = require
12-
13-
module(...)
14-
15-
local dis_mips = require(_PACKAGE.."dis_mips")
16-
17-
create = dis_mips.create_el
18-
disass = dis_mips.disass_el
19-
regname = dis_mips.regname
11+
local dis_mips = require((string.match(..., ".*%.") or "").."dis_mips")
12+
return {
13+
create = dis_mips.create_el,
14+
disass = dis_mips.disass_el,
15+
regname = dis_mips.regname
16+
}
2017

0 commit comments

Comments
 (0)