This commit is contained in:
Miku AuahDark
2023-04-18 10:25:19 +08:00
parent c8ebfc3427
commit 5187166c3d
296 changed files with 1734 additions and 1082 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
=============================================================================== ===============================================================================
LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/ LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/
Copyright (C) 2005-2021 Mike Pall. All rights reserved. Copyright (C) 2005-2022 Mike Pall. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+6 -2
View File
@@ -10,7 +10,7 @@
# For MSVC, please follow the instructions given in src/msvcbuild.bat. # For MSVC, please follow the instructions given in src/msvcbuild.bat.
# For MinGW and Cygwin, cd to src and run make with the Makefile there. # For MinGW and Cygwin, cd to src and run make with the Makefile there.
# #
# Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h # Copyright (C) 2005-2022 Mike Pall. See Copyright Notice in luajit.h
############################################################################## ##############################################################################
MAJVER= 2 MAJVER= 2
@@ -33,7 +33,8 @@ DPREFIX= $(DESTDIR)$(PREFIX)
INSTALL_BIN= $(DPREFIX)/bin INSTALL_BIN= $(DPREFIX)/bin
INSTALL_LIB= $(DPREFIX)/$(MULTILIB) INSTALL_LIB= $(DPREFIX)/$(MULTILIB)
INSTALL_SHARE= $(DPREFIX)/share INSTALL_SHARE= $(DPREFIX)/share
INSTALL_INC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER) INSTALL_DEFINC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER)
INSTALL_INC= $(INSTALL_DEFINC)
INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION) INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION)
INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit
@@ -78,6 +79,9 @@ UNINSTALL= $(RM)
LDCONFIG= ldconfig -n 2>/dev/null LDCONFIG= ldconfig -n 2>/dev/null
SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \ SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \
-e "s|^multilib=.*|multilib=$(MULTILIB)|" -e "s|^multilib=.*|multilib=$(MULTILIB)|"
ifneq ($(INSTALL_DEFINC),$(INSTALL_INC))
SED_PC+= -e "s|^includedir=.*|includedir=$(INSTALL_INC)|"
endif
FILE_T= luajit FILE_T= luajit
FILE_A= libluajit.a FILE_A= libluajit.a
+1 -1
View File
@@ -5,7 +5,7 @@ LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.
Project Homepage: https://luajit.org/ Project Homepage: https://luajit.org/
LuaJIT is Copyright (C) 2005-2021 Mike Pall. LuaJIT is Copyright (C) 2005-2022 Mike Pall.
LuaJIT is free software, released under the MIT license. LuaJIT is free software, released under the MIT license.
See full Copyright Notice in the COPYRIGHT file or in luajit.h. See full Copyright Notice in the COPYRIGHT file or in luajit.h.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT bytecode listing module. -- LuaJIT bytecode listing module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT module to save/list bytecode. -- LuaJIT module to save/list bytecode.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -33,6 +33,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
-t type Set output file type (default: auto-detect from output name). -t type Set output file type (default: auto-detect from output name).
-a arch Override architecture for object files (default: native). -a arch Override architecture for object files (default: native).
-o os Override OS for object files (default: native). -o os Override OS for object files (default: native).
-F name Override filename (default: input filename).
-e chunk Use chunk string as input. -e chunk Use chunk string as input.
-- Stop handling options. -- Stop handling options.
- Use stdin as input and/or stdout as output. - Use stdin as input and/or stdout as output.
@@ -49,10 +50,22 @@ local function check(ok, ...)
os.exit(1) os.exit(1)
end end
local function readfile(input) local function readfile(ctx, input)
if type(input) == "function" then return input end if type(input) == "function" then return input end
if input == "-" then input = nil end if ctx.filename then
return check(loadfile(input)) local data
if input == "-" then
data = io.stdin:read("*a")
else
local fp = assert(io.open(input, "rb"))
data = assert(fp:read("*a"))
assert(fp:close())
end
return check(load(data, ctx.filename))
else
if input == "-" then input = nil end
return check(loadfile(input))
end
end end
local function savefile(name, mode) local function savefile(name, mode)
@@ -456,18 +469,18 @@ typedef struct {
uint32_t value; uint32_t value;
} mach_nlist; } mach_nlist;
typedef struct { typedef struct {
uint32_t strx; int32_t strx;
uint8_t type, sect; uint8_t type, sect;
uint16_t desc; uint16_t desc;
uint64_t value; uint64_t value;
} mach_nlist_64; } mach_nlist_64;
typedef struct typedef struct
{ {
uint32_t magic, nfat_arch; int32_t magic, nfat_arch;
} mach_fat_header; } mach_fat_header;
typedef struct typedef struct
{ {
uint32_t cputype, cpusubtype, offset, size, align; int32_t cputype, cpusubtype, offset, size, align;
} mach_fat_arch; } mach_fat_arch;
typedef struct { typedef struct {
struct { struct {
@@ -501,6 +514,18 @@ typedef struct {
mach_nlist sym_entry; mach_nlist sym_entry;
uint8_t space[4096]; uint8_t space[4096];
} mach_fat_obj; } mach_fat_obj;
typedef struct {
mach_fat_header fat;
mach_fat_arch fat_arch[2];
struct {
mach_header_64 hdr;
mach_segment_command_64 seg;
mach_section_64 sec;
mach_symtab_command sym;
} arch[2];
mach_nlist_64 sym_entry;
uint8_t space[4096];
} mach_fat_obj_64;
]] ]]
local symname = '_'..LJBC_PREFIX..ctx.modname local symname = '_'..LJBC_PREFIX..ctx.modname
local isfat, is64, align, mobj = false, false, 4, "mach_obj" local isfat, is64, align, mobj = false, false, 4, "mach_obj"
@@ -509,7 +534,7 @@ typedef struct {
elseif ctx.arch == "arm" then elseif ctx.arch == "arm" then
isfat, mobj = true, "mach_fat_obj" isfat, mobj = true, "mach_fat_obj"
elseif ctx.arch == "arm64" then elseif ctx.arch == "arm64" then
is64, align, isfat, mobj = true, 8, true, "mach_fat_obj" is64, align, isfat, mobj = true, 8, true, "mach_fat_obj_64"
else else
check(ctx.arch == "x86", "unsupported architecture for OSX") check(ctx.arch == "x86", "unsupported architecture for OSX")
end end
@@ -592,13 +617,13 @@ end
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
local function bclist(input, output) local function bclist(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
require("jit.bc").dump(f, savefile(output, "w"), true) require("jit.bc").dump(f, savefile(output, "w"), true)
end end
local function bcsave(ctx, input, output) local function bcsave(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
local s = string.dump(f, ctx.strip) local s = string.dump(f, ctx.strip)
local t = ctx.type local t = ctx.type
if not t then if not t then
@@ -651,6 +676,8 @@ local function docmd(...)
ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture") ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture")
elseif opt == "o" then elseif opt == "o" then
ctx.os = checkarg(tremove(arg, n), map_os, "OS name") ctx.os = checkarg(tremove(arg, n), map_os, "OS name")
elseif opt == "F" then
ctx.filename = "@"..tremove(arg, n)
else else
usage() usage()
end end
@@ -662,7 +689,7 @@ local function docmd(...)
end end
if list then if list then
if #arg == 0 or #arg > 2 then usage() end if #arg == 0 or #arg > 2 then usage() end
bclist(arg[1], arg[2] or "-") bclist(ctx, arg[1], arg[2] or "-")
else else
if #arg ~= 2 then usage() end if #arg ~= 2 then usage() end
bcsave(ctx, arg[1], arg[2]) bcsave(ctx, arg[1], arg[2])
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM disassembler module. -- LuaJIT ARM disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64 disassembler module. -- LuaJIT ARM64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
-- --
-- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com. -- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64BE disassembler wrapper module. -- LuaJIT ARM64BE disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- ARM64 instructions are always little-endian. So just forward to the -- ARM64 instructions are always little-endian. So just forward to the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS disassembler module. -- LuaJIT MIPS disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64 disassembler wrapper module. -- LuaJIT MIPS64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the big-endian functions from the -- This module just exports the big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64EL disassembler wrapper module. -- LuaJIT MIPS64EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6 disassembler wrapper module. -- LuaJIT MIPS64R6 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 big-endian functions from the -- This module just exports the r6 big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6EL disassembler wrapper module. -- LuaJIT MIPS64R6EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 little-endian functions from the -- This module just exports the r6 little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPSEL disassembler wrapper module. -- LuaJIT MIPSEL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT PPC disassembler module. -- LuaJIT PPC disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x64 disassembler wrapper module. -- LuaJIT x64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the 64 bit functions from the combined -- This module just exports the 64 bit functions from the combined
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x86/x64 disassembler module. -- LuaJIT x86/x64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT compiler dump module. -- LuaJIT compiler dump module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler. -- LuaJIT profiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- Verbose mode of the LuaJIT compiler. -- Verbose mode of the LuaJIT compiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -76,7 +76,6 @@ ircall = {
"sqrt", "sqrt",
"log", "log",
"lj_vm_log2", "lj_vm_log2",
"lj_vm_powi",
"pow", "pow",
"atan2", "atan2",
"ldexp", "ldexp",
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler zones. -- LuaJIT profiler zones.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT bytecode listing module. -- LuaJIT bytecode listing module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT module to save/list bytecode. -- LuaJIT module to save/list bytecode.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -33,6 +33,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
-t type Set output file type (default: auto-detect from output name). -t type Set output file type (default: auto-detect from output name).
-a arch Override architecture for object files (default: native). -a arch Override architecture for object files (default: native).
-o os Override OS for object files (default: native). -o os Override OS for object files (default: native).
-F name Override filename (default: input filename).
-e chunk Use chunk string as input. -e chunk Use chunk string as input.
-- Stop handling options. -- Stop handling options.
- Use stdin as input and/or stdout as output. - Use stdin as input and/or stdout as output.
@@ -49,10 +50,22 @@ local function check(ok, ...)
os.exit(1) os.exit(1)
end end
local function readfile(input) local function readfile(ctx, input)
if type(input) == "function" then return input end if type(input) == "function" then return input end
if input == "-" then input = nil end if ctx.filename then
return check(loadfile(input)) local data
if input == "-" then
data = io.stdin:read("*a")
else
local fp = assert(io.open(input, "rb"))
data = assert(fp:read("*a"))
assert(fp:close())
end
return check(load(data, ctx.filename))
else
if input == "-" then input = nil end
return check(loadfile(input))
end
end end
local function savefile(name, mode) local function savefile(name, mode)
@@ -456,18 +469,18 @@ typedef struct {
uint32_t value; uint32_t value;
} mach_nlist; } mach_nlist;
typedef struct { typedef struct {
uint32_t strx; int32_t strx;
uint8_t type, sect; uint8_t type, sect;
uint16_t desc; uint16_t desc;
uint64_t value; uint64_t value;
} mach_nlist_64; } mach_nlist_64;
typedef struct typedef struct
{ {
uint32_t magic, nfat_arch; int32_t magic, nfat_arch;
} mach_fat_header; } mach_fat_header;
typedef struct typedef struct
{ {
uint32_t cputype, cpusubtype, offset, size, align; int32_t cputype, cpusubtype, offset, size, align;
} mach_fat_arch; } mach_fat_arch;
typedef struct { typedef struct {
struct { struct {
@@ -501,6 +514,18 @@ typedef struct {
mach_nlist sym_entry; mach_nlist sym_entry;
uint8_t space[4096]; uint8_t space[4096];
} mach_fat_obj; } mach_fat_obj;
typedef struct {
mach_fat_header fat;
mach_fat_arch fat_arch[2];
struct {
mach_header_64 hdr;
mach_segment_command_64 seg;
mach_section_64 sec;
mach_symtab_command sym;
} arch[2];
mach_nlist_64 sym_entry;
uint8_t space[4096];
} mach_fat_obj_64;
]] ]]
local symname = '_'..LJBC_PREFIX..ctx.modname local symname = '_'..LJBC_PREFIX..ctx.modname
local isfat, is64, align, mobj = false, false, 4, "mach_obj" local isfat, is64, align, mobj = false, false, 4, "mach_obj"
@@ -509,7 +534,7 @@ typedef struct {
elseif ctx.arch == "arm" then elseif ctx.arch == "arm" then
isfat, mobj = true, "mach_fat_obj" isfat, mobj = true, "mach_fat_obj"
elseif ctx.arch == "arm64" then elseif ctx.arch == "arm64" then
is64, align, isfat, mobj = true, 8, true, "mach_fat_obj" is64, align, isfat, mobj = true, 8, true, "mach_fat_obj_64"
else else
check(ctx.arch == "x86", "unsupported architecture for OSX") check(ctx.arch == "x86", "unsupported architecture for OSX")
end end
@@ -592,13 +617,13 @@ end
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
local function bclist(input, output) local function bclist(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
require("jit.bc").dump(f, savefile(output, "w"), true) require("jit.bc").dump(f, savefile(output, "w"), true)
end end
local function bcsave(ctx, input, output) local function bcsave(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
local s = string.dump(f, ctx.strip) local s = string.dump(f, ctx.strip)
local t = ctx.type local t = ctx.type
if not t then if not t then
@@ -651,6 +676,8 @@ local function docmd(...)
ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture") ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture")
elseif opt == "o" then elseif opt == "o" then
ctx.os = checkarg(tremove(arg, n), map_os, "OS name") ctx.os = checkarg(tremove(arg, n), map_os, "OS name")
elseif opt == "F" then
ctx.filename = "@"..tremove(arg, n)
else else
usage() usage()
end end
@@ -662,7 +689,7 @@ local function docmd(...)
end end
if list then if list then
if #arg == 0 or #arg > 2 then usage() end if #arg == 0 or #arg > 2 then usage() end
bclist(arg[1], arg[2] or "-") bclist(ctx, arg[1], arg[2] or "-")
else else
if #arg ~= 2 then usage() end if #arg ~= 2 then usage() end
bcsave(ctx, arg[1], arg[2]) bcsave(ctx, arg[1], arg[2])
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM disassembler module. -- LuaJIT ARM disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64 disassembler module. -- LuaJIT ARM64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
-- --
-- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com. -- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64BE disassembler wrapper module. -- LuaJIT ARM64BE disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- ARM64 instructions are always little-endian. So just forward to the -- ARM64 instructions are always little-endian. So just forward to the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS disassembler module. -- LuaJIT MIPS disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64 disassembler wrapper module. -- LuaJIT MIPS64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the big-endian functions from the -- This module just exports the big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64EL disassembler wrapper module. -- LuaJIT MIPS64EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6 disassembler wrapper module. -- LuaJIT MIPS64R6 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 big-endian functions from the -- This module just exports the r6 big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6EL disassembler wrapper module. -- LuaJIT MIPS64R6EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 little-endian functions from the -- This module just exports the r6 little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPSEL disassembler wrapper module. -- LuaJIT MIPSEL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT PPC disassembler module. -- LuaJIT PPC disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x64 disassembler wrapper module. -- LuaJIT x64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the 64 bit functions from the combined -- This module just exports the 64 bit functions from the combined
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x86/x64 disassembler module. -- LuaJIT x86/x64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT compiler dump module. -- LuaJIT compiler dump module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler. -- LuaJIT profiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- Verbose mode of the LuaJIT compiler. -- Verbose mode of the LuaJIT compiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -76,7 +76,6 @@ ircall = {
"sqrt", "sqrt",
"log", "log",
"lj_vm_log2", "lj_vm_log2",
"lj_vm_powi",
"pow", "pow",
"atan2", "atan2",
"ldexp", "ldexp",
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler zones. -- LuaJIT profiler zones.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT bytecode listing module. -- LuaJIT bytecode listing module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT module to save/list bytecode. -- LuaJIT module to save/list bytecode.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -33,6 +33,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
-t type Set output file type (default: auto-detect from output name). -t type Set output file type (default: auto-detect from output name).
-a arch Override architecture for object files (default: native). -a arch Override architecture for object files (default: native).
-o os Override OS for object files (default: native). -o os Override OS for object files (default: native).
-F name Override filename (default: input filename).
-e chunk Use chunk string as input. -e chunk Use chunk string as input.
-- Stop handling options. -- Stop handling options.
- Use stdin as input and/or stdout as output. - Use stdin as input and/or stdout as output.
@@ -49,10 +50,22 @@ local function check(ok, ...)
os.exit(1) os.exit(1)
end end
local function readfile(input) local function readfile(ctx, input)
if type(input) == "function" then return input end if type(input) == "function" then return input end
if input == "-" then input = nil end if ctx.filename then
return check(loadfile(input)) local data
if input == "-" then
data = io.stdin:read("*a")
else
local fp = assert(io.open(input, "rb"))
data = assert(fp:read("*a"))
assert(fp:close())
end
return check(load(data, ctx.filename))
else
if input == "-" then input = nil end
return check(loadfile(input))
end
end end
local function savefile(name, mode) local function savefile(name, mode)
@@ -456,18 +469,18 @@ typedef struct {
uint32_t value; uint32_t value;
} mach_nlist; } mach_nlist;
typedef struct { typedef struct {
uint32_t strx; int32_t strx;
uint8_t type, sect; uint8_t type, sect;
uint16_t desc; uint16_t desc;
uint64_t value; uint64_t value;
} mach_nlist_64; } mach_nlist_64;
typedef struct typedef struct
{ {
uint32_t magic, nfat_arch; int32_t magic, nfat_arch;
} mach_fat_header; } mach_fat_header;
typedef struct typedef struct
{ {
uint32_t cputype, cpusubtype, offset, size, align; int32_t cputype, cpusubtype, offset, size, align;
} mach_fat_arch; } mach_fat_arch;
typedef struct { typedef struct {
struct { struct {
@@ -501,6 +514,18 @@ typedef struct {
mach_nlist sym_entry; mach_nlist sym_entry;
uint8_t space[4096]; uint8_t space[4096];
} mach_fat_obj; } mach_fat_obj;
typedef struct {
mach_fat_header fat;
mach_fat_arch fat_arch[2];
struct {
mach_header_64 hdr;
mach_segment_command_64 seg;
mach_section_64 sec;
mach_symtab_command sym;
} arch[2];
mach_nlist_64 sym_entry;
uint8_t space[4096];
} mach_fat_obj_64;
]] ]]
local symname = '_'..LJBC_PREFIX..ctx.modname local symname = '_'..LJBC_PREFIX..ctx.modname
local isfat, is64, align, mobj = false, false, 4, "mach_obj" local isfat, is64, align, mobj = false, false, 4, "mach_obj"
@@ -509,7 +534,7 @@ typedef struct {
elseif ctx.arch == "arm" then elseif ctx.arch == "arm" then
isfat, mobj = true, "mach_fat_obj" isfat, mobj = true, "mach_fat_obj"
elseif ctx.arch == "arm64" then elseif ctx.arch == "arm64" then
is64, align, isfat, mobj = true, 8, true, "mach_fat_obj" is64, align, isfat, mobj = true, 8, true, "mach_fat_obj_64"
else else
check(ctx.arch == "x86", "unsupported architecture for OSX") check(ctx.arch == "x86", "unsupported architecture for OSX")
end end
@@ -592,13 +617,13 @@ end
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
local function bclist(input, output) local function bclist(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
require("jit.bc").dump(f, savefile(output, "w"), true) require("jit.bc").dump(f, savefile(output, "w"), true)
end end
local function bcsave(ctx, input, output) local function bcsave(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
local s = string.dump(f, ctx.strip) local s = string.dump(f, ctx.strip)
local t = ctx.type local t = ctx.type
if not t then if not t then
@@ -651,6 +676,8 @@ local function docmd(...)
ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture") ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture")
elseif opt == "o" then elseif opt == "o" then
ctx.os = checkarg(tremove(arg, n), map_os, "OS name") ctx.os = checkarg(tremove(arg, n), map_os, "OS name")
elseif opt == "F" then
ctx.filename = "@"..tremove(arg, n)
else else
usage() usage()
end end
@@ -662,7 +689,7 @@ local function docmd(...)
end end
if list then if list then
if #arg == 0 or #arg > 2 then usage() end if #arg == 0 or #arg > 2 then usage() end
bclist(arg[1], arg[2] or "-") bclist(ctx, arg[1], arg[2] or "-")
else else
if #arg ~= 2 then usage() end if #arg ~= 2 then usage() end
bcsave(ctx, arg[1], arg[2]) bcsave(ctx, arg[1], arg[2])
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM disassembler module. -- LuaJIT ARM disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64 disassembler module. -- LuaJIT ARM64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
-- --
-- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com. -- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64BE disassembler wrapper module. -- LuaJIT ARM64BE disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- ARM64 instructions are always little-endian. So just forward to the -- ARM64 instructions are always little-endian. So just forward to the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS disassembler module. -- LuaJIT MIPS disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64 disassembler wrapper module. -- LuaJIT MIPS64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the big-endian functions from the -- This module just exports the big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64EL disassembler wrapper module. -- LuaJIT MIPS64EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6 disassembler wrapper module. -- LuaJIT MIPS64R6 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 big-endian functions from the -- This module just exports the r6 big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6EL disassembler wrapper module. -- LuaJIT MIPS64R6EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 little-endian functions from the -- This module just exports the r6 little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPSEL disassembler wrapper module. -- LuaJIT MIPSEL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT PPC disassembler module. -- LuaJIT PPC disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x64 disassembler wrapper module. -- LuaJIT x64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the 64 bit functions from the combined -- This module just exports the 64 bit functions from the combined
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x86/x64 disassembler module. -- LuaJIT x86/x64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT compiler dump module. -- LuaJIT compiler dump module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler. -- LuaJIT profiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- Verbose mode of the LuaJIT compiler. -- Verbose mode of the LuaJIT compiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -76,7 +76,6 @@ ircall = {
"sqrt", "sqrt",
"log", "log",
"lj_vm_log2", "lj_vm_log2",
"lj_vm_powi",
"pow", "pow",
"atan2", "atan2",
"ldexp", "ldexp",
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler zones. -- LuaJIT profiler zones.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
Binary file not shown.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT bytecode listing module. -- LuaJIT bytecode listing module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT module to save/list bytecode. -- LuaJIT module to save/list bytecode.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -33,6 +33,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
-t type Set output file type (default: auto-detect from output name). -t type Set output file type (default: auto-detect from output name).
-a arch Override architecture for object files (default: native). -a arch Override architecture for object files (default: native).
-o os Override OS for object files (default: native). -o os Override OS for object files (default: native).
-F name Override filename (default: input filename).
-e chunk Use chunk string as input. -e chunk Use chunk string as input.
-- Stop handling options. -- Stop handling options.
- Use stdin as input and/or stdout as output. - Use stdin as input and/or stdout as output.
@@ -49,10 +50,22 @@ local function check(ok, ...)
os.exit(1) os.exit(1)
end end
local function readfile(input) local function readfile(ctx, input)
if type(input) == "function" then return input end if type(input) == "function" then return input end
if input == "-" then input = nil end if ctx.filename then
return check(loadfile(input)) local data
if input == "-" then
data = io.stdin:read("*a")
else
local fp = assert(io.open(input, "rb"))
data = assert(fp:read("*a"))
assert(fp:close())
end
return check(load(data, ctx.filename))
else
if input == "-" then input = nil end
return check(loadfile(input))
end
end end
local function savefile(name, mode) local function savefile(name, mode)
@@ -456,18 +469,18 @@ typedef struct {
uint32_t value; uint32_t value;
} mach_nlist; } mach_nlist;
typedef struct { typedef struct {
uint32_t strx; int32_t strx;
uint8_t type, sect; uint8_t type, sect;
uint16_t desc; uint16_t desc;
uint64_t value; uint64_t value;
} mach_nlist_64; } mach_nlist_64;
typedef struct typedef struct
{ {
uint32_t magic, nfat_arch; int32_t magic, nfat_arch;
} mach_fat_header; } mach_fat_header;
typedef struct typedef struct
{ {
uint32_t cputype, cpusubtype, offset, size, align; int32_t cputype, cpusubtype, offset, size, align;
} mach_fat_arch; } mach_fat_arch;
typedef struct { typedef struct {
struct { struct {
@@ -501,6 +514,18 @@ typedef struct {
mach_nlist sym_entry; mach_nlist sym_entry;
uint8_t space[4096]; uint8_t space[4096];
} mach_fat_obj; } mach_fat_obj;
typedef struct {
mach_fat_header fat;
mach_fat_arch fat_arch[2];
struct {
mach_header_64 hdr;
mach_segment_command_64 seg;
mach_section_64 sec;
mach_symtab_command sym;
} arch[2];
mach_nlist_64 sym_entry;
uint8_t space[4096];
} mach_fat_obj_64;
]] ]]
local symname = '_'..LJBC_PREFIX..ctx.modname local symname = '_'..LJBC_PREFIX..ctx.modname
local isfat, is64, align, mobj = false, false, 4, "mach_obj" local isfat, is64, align, mobj = false, false, 4, "mach_obj"
@@ -509,7 +534,7 @@ typedef struct {
elseif ctx.arch == "arm" then elseif ctx.arch == "arm" then
isfat, mobj = true, "mach_fat_obj" isfat, mobj = true, "mach_fat_obj"
elseif ctx.arch == "arm64" then elseif ctx.arch == "arm64" then
is64, align, isfat, mobj = true, 8, true, "mach_fat_obj" is64, align, isfat, mobj = true, 8, true, "mach_fat_obj_64"
else else
check(ctx.arch == "x86", "unsupported architecture for OSX") check(ctx.arch == "x86", "unsupported architecture for OSX")
end end
@@ -592,13 +617,13 @@ end
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
local function bclist(input, output) local function bclist(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
require("jit.bc").dump(f, savefile(output, "w"), true) require("jit.bc").dump(f, savefile(output, "w"), true)
end end
local function bcsave(ctx, input, output) local function bcsave(ctx, input, output)
local f = readfile(input) local f = readfile(ctx, input)
local s = string.dump(f, ctx.strip) local s = string.dump(f, ctx.strip)
local t = ctx.type local t = ctx.type
if not t then if not t then
@@ -651,6 +676,8 @@ local function docmd(...)
ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture") ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture")
elseif opt == "o" then elseif opt == "o" then
ctx.os = checkarg(tremove(arg, n), map_os, "OS name") ctx.os = checkarg(tremove(arg, n), map_os, "OS name")
elseif opt == "F" then
ctx.filename = "@"..tremove(arg, n)
else else
usage() usage()
end end
@@ -662,7 +689,7 @@ local function docmd(...)
end end
if list then if list then
if #arg == 0 or #arg > 2 then usage() end if #arg == 0 or #arg > 2 then usage() end
bclist(arg[1], arg[2] or "-") bclist(ctx, arg[1], arg[2] or "-")
else else
if #arg ~= 2 then usage() end if #arg ~= 2 then usage() end
bcsave(ctx, arg[1], arg[2]) bcsave(ctx, arg[1], arg[2])
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM disassembler module. -- LuaJIT ARM disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64 disassembler module. -- LuaJIT ARM64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
-- --
-- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com. -- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT ARM64BE disassembler wrapper module. -- LuaJIT ARM64BE disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- ARM64 instructions are always little-endian. So just forward to the -- ARM64 instructions are always little-endian. So just forward to the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS disassembler module. -- LuaJIT MIPS disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64 disassembler wrapper module. -- LuaJIT MIPS64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the big-endian functions from the -- This module just exports the big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64EL disassembler wrapper module. -- LuaJIT MIPS64EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6 disassembler wrapper module. -- LuaJIT MIPS64R6 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 big-endian functions from the -- This module just exports the r6 big-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPS64R6EL disassembler wrapper module. -- LuaJIT MIPS64R6EL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the r6 little-endian functions from the -- This module just exports the r6 little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT MIPSEL disassembler wrapper module. -- LuaJIT MIPSEL disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the little-endian functions from the -- This module just exports the little-endian functions from the
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT PPC disassembler module. -- LuaJIT PPC disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT/X license. See Copyright Notice in luajit.h -- Released under the MIT/X license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x64 disassembler wrapper module. -- LuaJIT x64 disassembler wrapper module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This module just exports the 64 bit functions from the combined -- This module just exports the 64 bit functions from the combined
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT x86/x64 disassembler module. -- LuaJIT x86/x64 disassembler module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- This is a helper module used by the LuaJIT machine code dumper module. -- This is a helper module used by the LuaJIT machine code dumper module.
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT compiler dump module. -- LuaJIT compiler dump module.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler. -- LuaJIT profiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- Verbose mode of the LuaJIT compiler. -- Verbose mode of the LuaJIT compiler.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
@@ -76,7 +76,6 @@ ircall = {
"sqrt", "sqrt",
"log", "log",
"lj_vm_log2", "lj_vm_log2",
"lj_vm_powi",
"pow", "pow",
"atan2", "atan2",
"ldexp", "ldexp",
@@ -1,7 +1,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- LuaJIT profiler zones. -- LuaJIT profiler zones.
-- --
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved. -- Copyright (C) 2005-2022 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h -- Released under the MIT license. See Copyright Notice in luajit.h
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- --
Binary file not shown.
+3 -12
View File
@@ -1,5 +1,5 @@
rem Build instruction assume using WSL + Clang for Windows (with MSVC x86+x64 toolset for -m32 switch) rem Build instruction assume using WSL + Clang for Windows (with MSVC x86+x64 toolset for -m32 switch)
rem This assume NDK r19 or later. See https://github.com/LuaJIT/LuaJIT/issues/477 for more information. rem This assume NDK r23c or later. See https://github.com/LuaJIT/LuaJIT/issues/477 for more information.
rem Make sure LuaJIT (yes, you need LuaJIT interpreter) and the NDK toolchain binaries is already in rem Make sure LuaJIT (yes, you need LuaJIT interpreter) and the NDK toolchain binaries is already in
rem your PATH environment variable. If you're confused which part of the NDK should be added your path: rem your PATH environment variable. If you're confused which part of the NDK should be added your path:
@@ -18,18 +18,9 @@ call :compile arm64-v8a aarch64-linux-android 21
if "%ERRORLEVEL%" == "1" goto :error if "%ERRORLEVEL%" == "1" goto :error
rem ARMv7 rem ARMv7
rem ARMv7 is complicated. call :compile armeabi-v7a armv7a-linux-androideabi 16 -m32
if exist android\armeabi-v7a\libluajit.a goto :x86
wsl make clean
if not "%ERRORLEVEL%" == "0" goto :error if not "%ERRORLEVEL%" == "0" goto :error
wsl make HOST_LUA=luajit.exe "HOST_CC=clang.exe -m32" HOST_CFLAGS=-D_CRT_SECURE_NO_WARNINGS CC=clang CROSS=arm-linux-androideabi- STATIC_CC=armv7a-linux-androideabi16-clang "DYNAMIC_CC=armv7a-linux-androideabi16-clang -fPIC" "TARGET_AR=arm-linux-androideabi-ar.exe rcus" TARGET_LD=armv7a-linux-androideabi16-clang TARGET_LDFLAGS=-fuse-ld=lld TARGET_STRIP=arm-linux-androideabi-strip.exe amalg -j4
if not "%ERRORLEVEL%" == "0" goto :error
copy src\libluajit.a android\armeabi-v7a\libluajit.a
if not "%ERRORLEVEL%" == "0" goto :error
xcopy src\jit android\armeabi-v7a\jit /I
del android\armeabi-v7a\jit\.gitignore
:x86
rem x86 rem x86
call :compile x86 i686-linux-android 16 -m32 call :compile x86 i686-linux-android 16 -m32
if not "%ERRORLEVEL%" == "0" goto :error if not "%ERRORLEVEL%" == "0" goto :error
@@ -44,7 +35,7 @@ goto :done
if exist android\%1\libluajit.a exit /b 0 if exist android\%1\libluajit.a exit /b 0
wsl make clean wsl make clean
if not "%ERRORLEVEL%" == "0" goto :error if not "%ERRORLEVEL%" == "0" goto :error
wsl make HOST_LUA=luajit.exe "HOST_CC=clang.exe %4" HOST_CFLAGS=-D_CRT_SECURE_NO_WARNINGS CC=clang CROSS=%2- "STATIC_CC=%2%3-clang -fPIC" "DYNAMIC_CC=%2%3-clang -fPIC" "TARGET_AR=%2-ar.exe rcus" TARGET_LD=%2%3-clang TARGET_LDFLAGS=-fuse-ld=lld TARGET_STRIP=%2-strip.exe amalg -j%NUMBER_OF_PROCESSORS% wsl make HOST_LUA=luajit.exe "HOST_CC=clang.exe %4" HOST_CFLAGS=-D_CRT_SECURE_NO_WARNINGS CC=clang CROSS=%2- "STATIC_CC=%2%3-clang -fPIC" "DYNAMIC_CC=%2%3-clang -fPIC" "TARGET_AR=llvm-ar.exe rcus" TARGET_LD=%2%3-clang TARGET_LDFLAGS=-fuse-ld=lld TARGET_STRIP=llvm-strip.exe amalg -j%NUMBER_OF_PROCESSORS%
if not "%ERRORLEVEL%" == "0" goto :error if not "%ERRORLEVEL%" == "0" goto :error
copy src\libluajit.a android\%1\libluajit.a copy src\libluajit.a android\%1\libluajit.a
if not "%ERRORLEVEL%" == "0" goto :error if not "%ERRORLEVEL%" == "0" goto :error
@@ -1,4 +1,4 @@
/* Copyright (C) 2004-2021 Mike Pall. /* Copyright (C) 2004-2022 Mike Pall.
* *
* You are welcome to use the general ideas of this design for your own sites. * You are welcome to use the general ideas of this design for your own sites.
* But please do not steal the stylesheet, the layout or the color scheme. * But please do not steal the stylesheet, the layout or the color scheme.
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2004-2021 Mike Pall. /* Copyright (C) 2004-2022 Mike Pall.
* *
* You are welcome to use the general ideas of this design for your own sites. * You are welcome to use the general ideas of this design for your own sites.
* But please do not steal the stylesheet, the layout or the color scheme. * But please do not steal the stylesheet, the layout or the color scheme.
+10 -5
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>Contact</title> <title>Contact</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -50,8 +50,6 @@
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -86,10 +84,17 @@ xD("fyZKB8xv\"FJytmz8.KAB0u52D")
</p> </p>
</noscript> </noscript>
<p><i>
Note: I cannot reply to GMail, Google Workplace, Outlook or Office365
mail addresses, since they prefer to mindlessly filter out mails sent
from small domains using independent mail servers, such as mine. If you
don't like that, please complain to Google or Microsoft, not me.
</i></p>
<h2>Copyright</h2> <h2>Copyright</h2>
<p> <p>
All documentation is All documentation is
Copyright &copy; 2005-2021 Mike Pall. Copyright &copy; 2005-2022 Mike Pall.
</p> </p>
@@ -97,7 +102,7 @@ Copyright &copy; 2005-2021 Mike Pall.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+12 -10
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>String Buffer Library</title> <title>String Buffer Library</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -61,8 +61,6 @@
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -86,7 +84,7 @@ overhead. In conjunction with the FFI library, they allow zero-copy
operations. operations.
</p> </p>
<p> <p>
The string buffer libary also includes a high-performance The string buffer library also includes a high-performance
<a href="serialize">serializer</a> for Lua objects. <a href="serialize">serializer</a> for Lua objects.
</p> </p>
@@ -434,8 +432,8 @@ unsupported object types, circular references or deeply nested tables.
<h3 id="buffer_decode"><tt>obj = buffer.decode(str)<br> <h3 id="buffer_decode"><tt>obj = buffer.decode(str)<br>
obj = buf:decode()</tt></h3> obj = buf:decode()</tt></h3>
<p> <p>
The stand-alone function de-serializes (decodes) the string The stand-alone function deserializes (decodes) the string
<tt>str</tt>, the buffer method de-serializes one object from the <tt>str</tt>, the buffer method deserializes one object from the
buffer. Both return a Lua object <tt>obj</tt>. buffer. Both return a Lua object <tt>obj</tt>.
</p> </p>
<p> <p>
@@ -448,6 +446,10 @@ encoded data. The stand-alone function throws when there's left-over
data after decoding a single top-level object. The buffer method leaves data after decoding a single top-level object. The buffer method leaves
any left-over data in the buffer. any left-over data in the buffer.
</p> </p>
<p>
Attempting to deserialize an FFI type will throw an error, if the FFI
library is not built-in or has not been loaded, yet.
</p>
<h3 id="serialize_options">Serialization Options</h3> <h3 id="serialize_options">Serialization Options</h3>
<p> <p>
@@ -458,7 +460,7 @@ the following members (all optional):
<li> <li>
<tt>dict</tt> is a Lua table holding a <b>dictionary of strings</b> that <tt>dict</tt> is a Lua table holding a <b>dictionary of strings</b> that
commonly occur as table keys of objects you are serializing. These keys commonly occur as table keys of objects you are serializing. These keys
are compactly encoded as indexes during serialization. A well chosen are compactly encoded as indexes during serialization. A well-chosen
dictionary saves space and improves serialization performance. dictionary saves space and improves serialization performance.
</li> </li>
<li> <li>
@@ -469,7 +471,7 @@ for the table objects you are serializing.
<p> <p>
<tt>dict</tt> needs to be an array of strings and <tt>metatable</tt> needs <tt>dict</tt> needs to be an array of strings and <tt>metatable</tt> needs
to be an array of tables. Both starting at index 1 and without holes (no to be an array of tables. Both starting at index 1 and without holes (no
<tt>nil</tt> inbetween). The tables are anchored in the buffer object and <tt>nil</tt> in between). The tables are anchored in the buffer object and
internally modified into a two-way index (don't do this yourself, just pass internally modified into a two-way index (don't do this yourself, just pass
a plain array). The tables must not be modified after they have been passed a plain array). The tables must not be modified after they have been passed
to <tt>buffer.new()</tt>. to <tt>buffer.new()</tt>.
@@ -620,7 +622,7 @@ errors are best caught with an outer wrapper for larger parts of code.
There's not much one can do after that, anyway. There's not much one can do after that, anyway.
</p> </p>
<p> <p>
OTOH you may want to catch some errors individually. Buffer methods need OTOH, you may want to catch some errors individually. Buffer methods need
to receive the buffer object as the first argument. The Lua colon-syntax to receive the buffer object as the first argument. The Lua colon-syntax
<tt>obj:method()</tt> does that implicitly. But to wrap a method with <tt>obj:method()</tt> does that implicitly. But to wrap a method with
<tt>pcall()</tt>, the arguments need to be passed like this: <tt>pcall()</tt>, the arguments need to be passed like this:
@@ -683,7 +685,7 @@ mappings of files are OK, but only if the file does not change.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+4 -6
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>Lua/C API Extensions</title> <title>Lua/C API Extensions</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -50,8 +50,6 @@
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -107,7 +105,7 @@ Turn the whole JIT compiler on or off or flush the whole cache of compiled code.
This sets the mode for the function at the stack index <tt>idx</tt> or This sets the mode for the function at the stack index <tt>idx</tt> or
the parent of the calling function (<tt>idx = 0</tt>). It either the parent of the calling function (<tt>idx = 0</tt>). It either
enables JIT compilation for a function, disables it and flushes any enables JIT compilation for a function, disables it and flushes any
already compiled code or only flushes already compiled code. This already compiled code, or only flushes already compiled code. This
applies recursively to all sub-functions of the function with applies recursively to all sub-functions of the function with
<tt>LUAJIT_MODE_ALLFUNC</tt> or only to the sub-functions with <tt>LUAJIT_MODE_ALLFUNC</tt> or only to the sub-functions with
<tt>LUAJIT_MODE_ALLSUBFUNC</tt>. <tt>LUAJIT_MODE_ALLSUBFUNC</tt>.
@@ -126,7 +124,7 @@ traces which link to it.
This mode defines a wrapper function for calls to C functions. If This mode defines a wrapper function for calls to C functions. If
called with <tt>LUAJIT_MODE_ON</tt>, the stack index at <tt>idx</tt> called with <tt>LUAJIT_MODE_ON</tt>, the stack index at <tt>idx</tt>
must be a <tt>lightuserdata</tt> object holding a pointer to the wrapper must be a <tt>lightuserdata</tt> object holding a pointer to the wrapper
function. From now on all C functions are called through the wrapper function. From now on, all C functions are called through the wrapper
function. If called with <tt>LUAJIT_MODE_OFF</tt> this mode is turned function. If called with <tt>LUAJIT_MODE_OFF</tt> this mode is turned
off and all C functions are directly called. off and all C functions are directly called.
</p> </p>
@@ -175,7 +173,7 @@ Also note that this mechanism is not without overhead.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+9 -11
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>FFI Library</title> <title>FFI Library</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -50,8 +50,6 @@
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -157,7 +155,7 @@ call the binding function. Phew!
<h2 id="cdata">Motivating Example: Using C Data Structures</h2> <h2 id="cdata">Motivating Example: Using C Data Structures</h2>
<p> <p>
The FFI library allows you to create and access C&nbsp;data The FFI library allows you to create and access C&nbsp;data
structures. Of course the main use for this is for interfacing with structures. Of course, the main use for this is for interfacing with
C&nbsp;functions. But they can be used stand-alone, too. C&nbsp;functions. But they can be used stand-alone, too.
</p> </p>
<p> <p>
@@ -169,7 +167,7 @@ implemented with a big table holding lots of tiny tables. This imposes
both a substantial memory overhead as well as a performance overhead. both a substantial memory overhead as well as a performance overhead.
</p> </p>
<p> <p>
Here's a sketch of a library that operates on color images plus a Here's a sketch of a library that operates on color images, plus a
simple benchmark. First, the plain Lua version: simple benchmark. First, the plain Lua version:
</p> </p>
<pre class="code"> <pre class="code">
@@ -184,7 +182,7 @@ local function image_ramp_green(n)
return img return img
end end
local function image_to_grey(img, n) local function image_to_gray(img, n)
for i=1,n do for i=1,n do
local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue) local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue)
img[i].red = y; img[i].green = y; img[i].blue = y img[i].red = y; img[i].green = y; img[i].blue = y
@@ -194,14 +192,14 @@ end
local N = 400*400 local N = 400*400
local img = image_ramp_green(N) local img = image_ramp_green(N)
for i=1,1000 do for i=1,1000 do
image_to_grey(img, N) image_to_gray(img, N)
end end
</pre> </pre>
<p> <p>
This creates a table with 160.000 pixels, each of which is a table This creates a table with 160.000 pixels, each of which is a table
holding four number values in the range of 0-255. First an image with holding four number values in the range of 0-255. First, an image with
a green ramp is created (1D for simplicity), then the image is a green ramp is created (1D for simplicity), then the image is
converted to greyscale 1000 times. Yes, that's silly, but I was in converted to grayscale 1000 times. Yes, that's silly, but I was in
need of a simple example ... need of a simple example ...
</p> </p>
<p> <p>
@@ -308,7 +306,7 @@ be more compact and faster. This is certainly true (by a factor of
~1.7x). Switching to a struct-of-arrays would help, too. ~1.7x). Switching to a struct-of-arrays would help, too.
</p> </p>
<p style="font-size: 8pt;"> <p style="font-size: 8pt;">
However the resulting code would be less idiomatic and rather However, the resulting code would be less idiomatic and rather
error-prone. And it still doesn't get even close to the performance of error-prone. And it still doesn't get even close to the performance of
the FFI version of the code. Also, high-level data structures cannot the FFI version of the code. Also, high-level data structures cannot
be easily passed to other C&nbsp;functions, especially I/O functions, be easily passed to other C&nbsp;functions, especially I/O functions,
@@ -318,7 +316,7 @@ without undue conversion penalties.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+7 -9
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>ffi.* API Functions</title> <title>ffi.* API Functions</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -55,8 +55,6 @@ td.abiparam { font-weight: bold; width: 6em; }
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -121,7 +119,7 @@ separated by semicolons. The trailing semicolon for a single
declaration may be omitted. declaration may be omitted.
</p> </p>
<p> <p>
Please note that external symbols are only <em>declared</em>, but they Please note, that external symbols are only <em>declared</em>, but they
are <em>not bound</em> to any specific address, yet. Binding is are <em>not bound</em> to any specific address, yet. Binding is
achieved with C&nbsp;library namespaces (see below). achieved with C&nbsp;library namespaces (see below).
</p> </p>
@@ -209,7 +207,7 @@ parse the cdecl only once and get its ctype with
<tt>ffi.typeof()</tt>. Then use the ctype as a constructor repeatedly. <tt>ffi.typeof()</tt>. Then use the ctype as a constructor repeatedly.
</p> </p>
<p style="font-size: 8pt;"> <p style="font-size: 8pt;">
Please note that an anonymous <tt>struct</tt> declaration implicitly Please note, that an anonymous <tt>struct</tt> declaration implicitly
creates a new and distinguished ctype every time you use it for creates a new and distinguished ctype every time you use it for
<tt>ffi.new()</tt>. This is probably <b>not</b> what you want, <tt>ffi.new()</tt>. This is probably <b>not</b> what you want,
especially if you create more than one cdata object. Different anonymous especially if you create more than one cdata object. Different anonymous
@@ -256,12 +254,12 @@ afterwards. Neither the contents of the <tt>metatable</tt> nor the
contents of an <tt>__index</tt> table (if any) may be modified contents of an <tt>__index</tt> table (if any) may be modified
afterwards. The associated metatable automatically applies to all uses afterwards. The associated metatable automatically applies to all uses
of this type, no matter how the objects are created or where they of this type, no matter how the objects are created or where they
originate from. Note that pre-defined operations on types have originate from. Note that predefined operations on types have
precedence (e.g. declared field names cannot be overridden). precedence (e.g. declared field names cannot be overridden).
</p> </p>
<p> <p>
All standard Lua metamethods are implemented. These are called directly, All standard Lua metamethods are implemented. These are called directly,
without shortcuts and on any mix of types. For binary operations, the without shortcuts, and on any mix of types. For binary operations, the
left operand is checked first for a valid ctype metamethod. The left operand is checked first for a valid ctype metamethod. The
<tt>__gc</tt> metamethod only applies to <tt>struct</tt>/<tt>union</tt> <tt>__gc</tt> metamethod only applies to <tt>struct</tt>/<tt>union</tt>
types and performs an implicit <a href="#ffi_gc"><tt>ffi.gc()</tt></a> types and performs an implicit <a href="#ffi_gc"><tt>ffi.gc()</tt></a>
@@ -492,7 +490,7 @@ have some extra methods:
<p> <p>
Free the resources associated with a callback. The associated Lua Free the resources associated with a callback. The associated Lua
function is unanchored and may be garbage collected. The callback function is unanchored and may be garbage collected. The callback
function pointer is no longer valid and must not be called anymore function pointer is no longer valid and must not be called again
(it may be reused by a subsequently created callback). (it may be reused by a subsequently created callback).
</p> </p>
@@ -558,7 +556,7 @@ named <tt>i</tt>.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
@@ -3,7 +3,7 @@
<head> <head>
<title>FFI Semantics</title> <title>FFI Semantics</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -55,8 +55,6 @@ td.convop { font-style: italic; width: 40%; }
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -88,7 +86,7 @@ footprint. It's used by the <a href="ext_ffi_api.html">ffi.* library
functions</a> to declare C&nbsp;types or external symbols. functions</a> to declare C&nbsp;types or external symbols.
</p> </p>
<p> <p>
It's only purpose is to parse C&nbsp;declarations, as found e.g. in Its only purpose is to parse C&nbsp;declarations, as found e.g. in
C&nbsp;header files. Although it does evaluate constant expressions, C&nbsp;header files. Although it does evaluate constant expressions,
it's <em>not</em> a C&nbsp;compiler. The body of <tt>inline</tt> it's <em>not</em> a C&nbsp;compiler. The body of <tt>inline</tt>
C&nbsp;function definitions is simply ignored. C&nbsp;function definitions is simply ignored.
@@ -165,7 +163,7 @@ function declarations.</li>
</ul> </ul>
<p> <p>
The following C&nbsp;types are pre-defined by the C&nbsp;parser (like The following C&nbsp;types are predefined by the C&nbsp;parser (like
a <tt>typedef</tt>, except re-declarations will be ignored): a <tt>typedef</tt>, except re-declarations will be ignored):
</p> </p>
<ul> <ul>
@@ -583,9 +581,9 @@ ffi.new("struct nested", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3
<h2 id="cdata_ops">Operations on cdata Objects</h2> <h2 id="cdata_ops">Operations on cdata Objects</h2>
<p> <p>
All of the standard Lua operators can be applied to cdata objects or a All standard Lua operators can be applied to cdata objects or a
mix of a cdata object and another Lua object. The following list shows mix of a cdata object and another Lua object. The following list shows
the pre-defined operations. the predefined operations.
</p> </p>
<p> <p>
Reference types are dereferenced <em>before</em> performing each of Reference types are dereferenced <em>before</em> performing each of
@@ -593,7 +591,7 @@ the operations below &mdash; the operation is applied to the
C&nbsp;type pointed to by the reference. C&nbsp;type pointed to by the reference.
</p> </p>
<p> <p>
The pre-defined operations are always tried first before deferring to a The predefined operations are always tried first before deferring to a
metamethod or index table (if any) for the corresponding ctype (except metamethod or index table (if any) for the corresponding ctype (except
for <tt>__new</tt>). An error is raised if the metamethod lookup or for <tt>__new</tt>). An error is raised if the metamethod lookup or
index table lookup fails. index table lookup fails.
@@ -643,7 +641,7 @@ assigning to an index of a vector raises an error.</li>
</ul> </ul>
<p> <p>
A ctype object can be indexed with a string key, too. The only A ctype object can be indexed with a string key, too. The only
pre-defined operation is reading scoped constants of predefined operation is reading scoped constants of
<tt>struct</tt>/<tt>union</tt> types. All other accesses defer <tt>struct</tt>/<tt>union</tt> types. All other accesses defer
to the corresponding metamethods or index tables (if any). to the corresponding metamethods or index tables (if any).
</p> </p>
@@ -656,7 +654,7 @@ certain optimizations.
<p> <p>
As a consequence, the <em>elements</em> of complex numbers and As a consequence, the <em>elements</em> of complex numbers and
vectors are immutable. But the elements of an aggregate holding these vectors are immutable. But the elements of an aggregate holding these
types <em>may</em> be modified of course. I.e. you cannot assign to types <em>may</em> be modified, of course. I.e. you cannot assign to
<tt>foo.c.im</tt>, but you can assign a (newly created) complex number <tt>foo.c.im</tt>, but you can assign a (newly created) complex number
to <tt>foo.c</tt>. to <tt>foo.c</tt>.
</p> </p>
@@ -675,8 +673,8 @@ through unions is explicitly detected and allowed.
to <tt>ffi.new(ct, ...)</tt>, unless a <tt>__new</tt> metamethod is to <tt>ffi.new(ct, ...)</tt>, unless a <tt>__new</tt> metamethod is
defined. The <tt>__new</tt> metamethod is called with the ctype object defined. The <tt>__new</tt> metamethod is called with the ctype object
plus any other arguments passed to the constructor. Note that you have to plus any other arguments passed to the constructor. Note that you have to
use <tt>ffi.new</tt> inside of it, since calling <tt>ct(...)</tt> would use <tt>ffi.new</tt> inside the metamethod, since calling <tt>ct(...)</tt>
cause infinite recursion.</li> would cause infinite recursion.</li>
<li><b>C&nbsp;function call</b>: a cdata function or cdata function <li><b>C&nbsp;function call</b>: a cdata function or cdata function
pointer can be called. The passed arguments are pointer can be called. The passed arguments are
@@ -687,7 +685,7 @@ variable argument part of vararg C&nbsp;function use
C&nbsp;function is called and the return value (if any) is C&nbsp;function is called and the return value (if any) is
<a href="#convert_tolua">converted to a Lua object</a>.<br> <a href="#convert_tolua">converted to a Lua object</a>.<br>
On Windows/x86 systems, <tt>__stdcall</tt> functions are automatically On Windows/x86 systems, <tt>__stdcall</tt> functions are automatically
detected and a function declared as <tt>__cdecl</tt> (the default) is detected, and a function declared as <tt>__cdecl</tt> (the default) is
silently fixed up after the first call.</li> silently fixed up after the first call.</li>
</ul> </ul>
@@ -697,7 +695,7 @@ silently fixed up after the first call.</li>
<li><b>Pointer arithmetic</b>: a cdata pointer/array and a cdata <li><b>Pointer arithmetic</b>: a cdata pointer/array and a cdata
number or a Lua number can be added or subtracted. The number must be number or a Lua number can be added or subtracted. The number must be
on the right hand side for a subtraction. The result is a pointer of on the right-hand side for a subtraction. The result is a pointer of
the same type with an address plus or minus the number value the same type with an address plus or minus the number value
multiplied by the element size in bytes. An error is raised if the multiplied by the element size in bytes. An error is raised if the
element size is undefined.</li> element size is undefined.</li>
@@ -712,7 +710,7 @@ operators (<tt>+&nbsp;-&nbsp;*&nbsp;/&nbsp;%&nbsp;^</tt> and unary
minus) can be applied to two cdata numbers, or a cdata number and a minus) can be applied to two cdata numbers, or a cdata number and a
Lua number. If one of them is an <tt>uint64_t</tt>, the other side is Lua number. If one of them is an <tt>uint64_t</tt>, the other side is
converted to an <tt>uint64_t</tt> and an unsigned arithmetic operation converted to an <tt>uint64_t</tt> and an unsigned arithmetic operation
is performed. Otherwise both sides are converted to an is performed. Otherwise, both sides are converted to an
<tt>int64_t</tt> and a signed arithmetic operation is performed. The <tt>int64_t</tt> and a signed arithmetic operation is performed. The
result is a boxed 64&nbsp;bit cdata object.<br> result is a boxed 64&nbsp;bit cdata object.<br>
@@ -759,7 +757,7 @@ which is compatible with any other pointer type.</li>
<li><b>64&nbsp;bit integer comparison</b>: two cdata numbers, or a <li><b>64&nbsp;bit integer comparison</b>: two cdata numbers, or a
cdata number and a Lua number can be compared with each other. If one cdata number and a Lua number can be compared with each other. If one
of them is an <tt>uint64_t</tt>, the other side is converted to an of them is an <tt>uint64_t</tt>, the other side is converted to an
<tt>uint64_t</tt> and an unsigned comparison is performed. Otherwise <tt>uint64_t</tt> and an unsigned comparison is performed. Otherwise,
both sides are converted to an <tt>int64_t</tt> and a signed both sides are converted to an <tt>int64_t</tt> and a signed
comparison is performed.<br> comparison is performed.<br>
@@ -784,9 +782,9 @@ keys!</b>
A cdata object is treated like any other garbage-collected object and A cdata object is treated like any other garbage-collected object and
is hashed and compared by its address for table indexing. Since is hashed and compared by its address for table indexing. Since
there's no interning for cdata value types, the same value may be there's no interning for cdata value types, the same value may be
boxed in different cdata objects with different addresses. Thus boxed in different cdata objects with different addresses. Thus,
<tt>t[1LL+1LL]</tt> and <tt>t[2LL]</tt> usually <b>do not</b> point to <tt>t[1LL+1LL]</tt> and <tt>t[2LL]</tt> usually <b>do not</b> point to
the same hash slot and they certainly <b>do not</b> point to the same the same hash slot, and they certainly <b>do not</b> point to the same
hash slot as <tt>t[2]</tt>. hash slot as <tt>t[2]</tt>.
</p> </p>
<p> <p>
@@ -808,7 +806,7 @@ the resulting Lua number as a key when indexing tables.<br>
One obvious benefit: <tt>t[tonumber(2LL)]</tt> <b>does</b> point to One obvious benefit: <tt>t[tonumber(2LL)]</tt> <b>does</b> point to
the same slot as <tt>t[2]</tt>.</li> the same slot as <tt>t[2]</tt>.</li>
<li>Otherwise use either <tt>tostring()</tt> on 64&nbsp;bit integers <li>Otherwise, use either <tt>tostring()</tt> on 64&nbsp;bit integers
or complex numbers or combine multiple fields of a cdata aggregate to or complex numbers or combine multiple fields of a cdata aggregate to
a Lua string (e.g. with a Lua string (e.g. with
<a href="ext_ffi_api.html#ffi_string"><tt>ffi.string()</tt></a>). Then <a href="ext_ffi_api.html#ffi_string"><tt>ffi.string()</tt></a>). Then
@@ -816,7 +814,7 @@ use the resulting Lua string as a key when indexing tables.</li>
<li>Create your own specialized hash table implementation using the <li>Create your own specialized hash table implementation using the
C&nbsp;types provided by the FFI library, just like you would in C&nbsp;types provided by the FFI library, just like you would in
C&nbsp;code. Ultimately this may give much better performance than the C&nbsp;code. Ultimately, this may give much better performance than the
other alternatives or what a generic by-value hash table could other alternatives or what a generic by-value hash table could
possibly provide.</li> possibly provide.</li>
@@ -882,7 +880,7 @@ garbage collector will automatically free the memory used by it (at
the end of the next GC cycle). the end of the next GC cycle).
</p> </p>
<p> <p>
Please note that pointers themselves are cdata objects, however they Please note, that pointers themselves are cdata objects, however they
are <b>not</b> followed by the garbage collector. So e.g. if you are <b>not</b> followed by the garbage collector. So e.g. if you
assign a cdata array to a pointer, you must keep the cdata object assign a cdata array to a pointer, you must keep the cdata object
holding the array alive as long as the pointer is still in use: holding the array alive as long as the pointer is still in use:
@@ -931,18 +929,18 @@ of the function pointer and the Lua function object (closure).
</p> </p>
<p> <p>
This can happen implicitly due to the usual conversions, e.g. when This can happen implicitly due to the usual conversions, e.g. when
passing a Lua function to a function pointer argument. Or you can use passing a Lua function to a function pointer argument. Or, you can use
<tt>ffi.cast()</tt> to explicitly cast a Lua function to a <tt>ffi.cast()</tt> to explicitly cast a Lua function to a
C&nbsp;function pointer. C&nbsp;function pointer.
</p> </p>
<p> <p>
Currently only certain C&nbsp;function types can be used as callback Currently, only certain C&nbsp;function types can be used as callback
functions. Neither C&nbsp;vararg functions nor functions with functions. Neither C&nbsp;vararg functions nor functions with
pass-by-value aggregate argument or result types are supported. There pass-by-value aggregate argument or result types are supported. There
are no restrictions for the kind of Lua functions that can be called are no restrictions on the kind of Lua functions that can be called
from the callback &mdash; no checks for the proper number of arguments from the callback &mdash; no checks for the proper number of arguments
are made. The return value of the Lua function will be converted to the are made. The return value of the Lua function will be converted to the
result type and an error will be thrown for invalid conversions. result type, and an error will be thrown for invalid conversions.
</p> </p>
<p> <p>
It's allowed to throw errors across a callback invocation, but it's not It's allowed to throw errors across a callback invocation, but it's not
@@ -1003,7 +1001,7 @@ convention cannot be automatically detected, unlike for
<tt>__stdcall</tt> calls <em>to</em> Windows functions. <tt>__stdcall</tt> calls <em>to</em> Windows functions.
</p> </p>
<p> <p>
For some use cases it's necessary to free up the resources or to For some use cases, it's necessary to free up the resources or to
dynamically redirect callbacks. Use an explicit cast to a dynamically redirect callbacks. Use an explicit cast to a
C&nbsp;function pointer and keep the resulting cdata object. Then use C&nbsp;function pointer and keep the resulting cdata object. Then use
the <a href="ext_ffi_api.html#callback_free"><tt>cb:free()</tt></a> the <a href="ext_ffi_api.html#callback_free"><tt>cb:free()</tt></a>
@@ -1056,7 +1054,7 @@ GUI application, which waits for user input most of the time, anyway.
</p> </p>
<p> <p>
For new designs <b>avoid push-style APIs</b>: a C&nbsp;function repeatedly For new designs <b>avoid push-style APIs</b>: a C&nbsp;function repeatedly
calling a callback for each result. Instead <b>use pull-style APIs</b>: calling a callback for each result. Instead, <b>use pull-style APIs</b>:
call a C&nbsp;function repeatedly to get a new result. Calls from Lua call a C&nbsp;function repeatedly to get a new result. Calls from Lua
to C via the FFI are much faster than the other way round. Most well-designed to C via the FFI are much faster than the other way round. Most well-designed
libraries already use pull-style APIs (read/write, get/put). libraries already use pull-style APIs (read/write, get/put).
@@ -1075,7 +1073,7 @@ function.
</p> </p>
<p> <p>
Indexing a C&nbsp;library namespace object with a symbol name (a Lua Indexing a C&nbsp;library namespace object with a symbol name (a Lua
string) automatically binds it to the library. First the symbol type string) automatically binds it to the library. First, the symbol type
is resolved &mdash; it must have been declared with is resolved &mdash; it must have been declared with
<a href="ext_ffi_api.html#ffi_cdef"><tt>ffi.cdef</tt></a>. Then the <a href="ext_ffi_api.html#ffi_cdef"><tt>ffi.cdef</tt></a>. Then the
symbol address is resolved by searching for the symbol name in the symbol address is resolved by searching for the symbol name in the
@@ -1130,7 +1128,7 @@ Performance notice: the JIT compiler specializes to the identity of
namespace objects and to the strings used to index it. This namespace objects and to the strings used to index it. This
effectively turns function cdata objects into constants. It's not effectively turns function cdata objects into constants. It's not
useful and actually counter-productive to explicitly cache these useful and actually counter-productive to explicitly cache these
function objects, e.g. <tt>local strlen = ffi.C.strlen</tt>. OTOH it function objects, e.g. <tt>local strlen = ffi.C.strlen</tt>. OTOH, it
<em>is</em> useful to cache the namespace itself, e.g. <tt>local C = <em>is</em> useful to cache the namespace itself, e.g. <tt>local C =
ffi.C</tt>. ffi.C</tt>.
</p> </p>
@@ -1155,14 +1153,14 @@ This behavior is inevitable, since the goal is to provide full
interoperability with C&nbsp;code. Adding extra safety measures, like interoperability with C&nbsp;code. Adding extra safety measures, like
bounds checks, would be futile. There's no way to detect bounds checks, would be futile. There's no way to detect
misdeclarations of C&nbsp;functions, since shared libraries only misdeclarations of C&nbsp;functions, since shared libraries only
provide symbol names, but no type information. Likewise there's no way provide symbol names, but no type information. Likewise, there's no way
to infer the valid range of indexes for a returned pointer. to infer the valid range of indexes for a returned pointer.
</p> </p>
<p> <p>
Again: the FFI library is a low-level library. This implies it needs Again: the FFI library is a low-level library. This implies it needs
to be used with care, but it's flexibility and performance often to be used with care, but it's flexibility and performance often
outweigh this concern. If you're a C or C++ developer, it'll be easy outweigh this concern. If you're a C or C++ developer, it'll be easy
to apply your existing knowledge. OTOH writing code for the FFI to apply your existing knowledge. OTOH, writing code for the FFI
library is not for the faint of heart and probably shouldn't be the library is not for the faint of heart and probably shouldn't be the
first exercise for someone with little experience in Lua, C or C++. first exercise for someone with little experience in Lua, C or C++.
</p> </p>
@@ -1190,7 +1188,7 @@ currently incomplete:
<li>C&nbsp;declarations are not passed through a C&nbsp;pre-processor, <li>C&nbsp;declarations are not passed through a C&nbsp;pre-processor,
yet.</li> yet.</li>
<li>The C&nbsp;parser is able to evaluate most constant expressions <li>The C&nbsp;parser is able to evaluate most constant expressions
commonly found in C&nbsp;header files. However it doesn't handle the commonly found in C&nbsp;header files. However, it doesn't handle the
full range of C&nbsp;expression semantics and may fail for some full range of C&nbsp;expression semantics and may fail for some
obscure constructs.</li> obscure constructs.</li>
<li><tt>static const</tt> declarations only work for integer types <li><tt>static const</tt> declarations only work for integer types
@@ -1248,7 +1246,7 @@ compiled.</li>
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
@@ -3,7 +3,7 @@
<head> <head>
<title>FFI Tutorial</title> <title>FFI Tutorial</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -57,8 +57,6 @@ td.idiomlua b { font-weight: normal; color: #2142bf; }
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -85,7 +83,7 @@ of its functions:
local ffi = require("ffi") local ffi = require("ffi")
</pre> </pre>
<p> <p>
Please note this doesn't define an <tt>ffi</tt> variable in the table Please note, this doesn't define an <tt>ffi</tt> variable in the table
of globals &mdash; you really need to use the local variable. The of globals &mdash; you really need to use the local variable. The
<tt>require</tt> function ensures the library is only loaded once. <tt>require</tt> function ensures the library is only loaded once.
</p> </p>
@@ -194,7 +192,7 @@ don't need to declare them as such.
<span class="mark">&#9316;</span> The <tt>poll()</tt> <span class="mark">&#9316;</span> The <tt>poll()</tt>
function takes a couple more arguments we're not going to use. You can function takes a couple more arguments we're not going to use. You can
simply use <tt>nil</tt> to pass a <tt>NULL</tt> pointer and <tt>0</tt> simply use <tt>nil</tt> to pass a <tt>NULL</tt> pointer and <tt>0</tt>
for the <tt>nfds</tt> parameter. Please note that the for the <tt>nfds</tt> parameter. Please note, that the
number&nbsp;<tt>0</tt> <em>does not convert to a pointer value</em>, number&nbsp;<tt>0</tt> <em>does not convert to a pointer value</em>,
unlike in C++. You really have to pass pointers to pointer arguments unlike in C++. You really have to pass pointers to pointer arguments
and numbers to number arguments. and numbers to number arguments.
@@ -291,12 +289,12 @@ Here's the step-by-step explanation:
<p> <p>
<span class="mark">&#9312;</span> This defines some of the <span class="mark">&#9312;</span> This defines some of the
C&nbsp;functions provided by zlib. For the sake of this example, some C&nbsp;functions provided by zlib. For the sake of this example, some
type indirections have been reduced and it uses the pre-defined type indirections have been reduced and it uses the predefined
fixed-size integer types, while still adhering to the zlib API/ABI. fixed-size integer types, while still adhering to the zlib API/ABI.
</p> </p>
<p> <p>
<span class="mark">&#9313;</span> This loads the zlib shared <span class="mark">&#9313;</span> This loads the zlib shared
library. On POSIX systems it's named <tt>libz.so</tt> and usually library. On POSIX systems, it's named <tt>libz.so</tt> and usually
comes pre-installed. Since <tt>ffi.load()</tt> automatically adds any comes pre-installed. Since <tt>ffi.load()</tt> automatically adds any
missing standard prefixes/suffixes, we can simply load the missing standard prefixes/suffixes, we can simply load the
<tt>"z"</tt> library. On Windows it's named <tt>zlib1.dll</tt> and <tt>"z"</tt> library. On Windows it's named <tt>zlib1.dll</tt> and
@@ -324,7 +322,7 @@ actual length that was used.
<p> <p>
In C you'd pass in the address of a local variable In C you'd pass in the address of a local variable
(<tt>&amp;buflen</tt>). But since there's no address-of operator in (<tt>&amp;buflen</tt>). But since there's no address-of operator in
Lua, we'll just pass in a one-element array. Conveniently it can be Lua, we'll just pass in a one-element array. Conveniently, it can be
initialized with the maximum buffer size in one step. Calling the initialized with the maximum buffer size in one step. Calling the
actual <tt>zlib.compress2</tt> function is then straightforward. actual <tt>zlib.compress2</tt> function is then straightforward.
</p> </p>
@@ -348,7 +346,7 @@ for garbage collection and string interning.
<span class="mark">&#9317;</span> The <tt>uncompress</tt> <span class="mark">&#9317;</span> The <tt>uncompress</tt>
functions does the exact opposite of the <tt>compress</tt> function. functions does the exact opposite of the <tt>compress</tt> function.
The compressed data doesn't include the size of the original string, The compressed data doesn't include the size of the original string,
so this needs to be passed in. Otherwise no surprises here. so this needs to be passed in. Otherwise, no surprises here.
</p> </p>
<p> <p>
<span class="mark">&#9318;</span> The code, that makes use <span class="mark">&#9318;</span> The code, that makes use
@@ -382,7 +380,7 @@ Ok, so the <tt>ffi.*</tt> functions generally accept cdata objects
wherever you'd want to use a number. That's why we get a away with wherever you'd want to use a number. That's why we get a away with
passing <tt>n</tt> to <tt>ffi.string()</tt> above. But other Lua passing <tt>n</tt> to <tt>ffi.string()</tt> above. But other Lua
library functions or modules don't know how to deal with this. So for library functions or modules don't know how to deal with this. So for
maximum portability one needs to use <tt>tonumber()</tt> on returned maximum portability, one needs to use <tt>tonumber()</tt> on returned
<tt>long</tt> results before passing them on. Otherwise the <tt>long</tt> results before passing them on. Otherwise the
application might work on some systems, but would fail in a POSIX/x64 application might work on some systems, but would fail in a POSIX/x64
environment. environment.
@@ -454,7 +452,7 @@ the origin.
</p> </p>
<p> <p>
<span class="mark">&#9315;</span> If we run out of operators, we can <span class="mark">&#9315;</span> If we run out of operators, we can
define named methods, too. Here the <tt>__index</tt> table defines an define named methods, too. Here, the <tt>__index</tt> table defines an
<tt>area</tt> function. For custom indexing needs, one might want to <tt>area</tt> function. For custom indexing needs, one might want to
define <tt>__index</tt> and <tt>__newindex</tt> <em>functions</em> instead. define <tt>__index</tt> and <tt>__newindex</tt> <em>functions</em> instead.
</p> </p>
@@ -468,13 +466,13 @@ be used e.g. to create an array of points. The metamethods automatically
apply to any and all uses of this type. apply to any and all uses of this type.
</p> </p>
<p> <p>
Please note that the association with a metatable is permanent and Please note, that the association with a metatable is permanent and
<b>the metatable must not be modified afterwards!</b> Ditto for the <b>the metatable must not be modified afterwards!</b> Ditto for the
<tt>__index</tt> table. <tt>__index</tt> table.
</p> </p>
<p> <p>
<span class="mark">&#9317;</span> Here are some simple usage examples <span class="mark">&#9317;</span> Here are some simple usage examples
for the point type and their expected results. The pre-defined for the point type and their expected results. The predefined
operations (such as <tt>a.x</tt>) can be freely mixed with the newly operations (such as <tt>a.x</tt>) can be freely mixed with the newly
defined metamethods. Note that <tt>area</tt> is a method and must be defined metamethods. Note that <tt>area</tt> is a method and must be
called with the Lua syntax for methods: <tt>a:area()</tt>, not called with the Lua syntax for methods: <tt>a:area()</tt>, not
@@ -483,7 +481,7 @@ called with the Lua syntax for methods: <tt>a:area()</tt>, not
<p> <p>
The C&nbsp;type metamethod mechanism is most useful when used in The C&nbsp;type metamethod mechanism is most useful when used in
conjunction with C&nbsp;libraries that are written in an object-oriented conjunction with C&nbsp;libraries that are written in an object-oriented
style. Creators return a pointer to a new instance and methods take an style. Creators return a pointer to a new instance, and methods take an
instance pointer as the first argument. Sometimes you can just point instance pointer as the first argument. Sometimes you can just point
<tt>__index</tt> to the library namespace and <tt>__gc</tt> to the <tt>__index</tt> to the library namespace and <tt>__gc</tt> to the
destructor and you're done. But often enough you'll want to add destructor and you're done. But often enough you'll want to add
@@ -569,7 +567,7 @@ end
</pre> </pre>
<p> <p>
This turns them into indirect calls and generates bigger and slower This turns them into indirect calls and generates bigger and slower
machine code. Instead you'll want to cache the namespace itself and machine code. Instead, you'll want to cache the namespace itself and
rely on the JIT compiler to eliminate the lookups: rely on the JIT compiler to eliminate the lookups:
</p> </p>
<pre class="code"> <pre class="code">
@@ -589,7 +587,7 @@ it to a local variable in the function scope is unnecessary.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+4 -6
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>jit.* Library</title> <title>jit.* Library</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -50,8 +50,6 @@
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -154,7 +152,7 @@ Contains the target architecture name:
<h2 id="jit_opt"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2> <h2 id="jit_opt"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2>
<p> <p>
This sub-module provides the backend for the <tt>-O</tt> command line This submodule provides the backend for the <tt>-O</tt> command line
option. option.
</p> </p>
<p> <p>
@@ -174,7 +172,7 @@ which was one of the ways to enable optimization.
<h2 id="jit_util"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2> <h2 id="jit_util"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2>
<p> <p>
This sub-module holds functions to introspect the bytecode, generated This submodule holds functions to introspect the bytecode, generated
traces, the IR and the generated machine code. The functionality traces, the IR and the generated machine code. The functionality
provided by this module is still in flux and therefore undocumented. provided by this module is still in flux and therefore undocumented.
</p> </p>
@@ -187,7 +185,7 @@ if you want to know more.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
@@ -3,7 +3,7 @@
<head> <head>
<title>Profiler</title> <title>Profiler</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -50,8 +50,6 @@
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -158,7 +156,7 @@ To see how much time is spent in different VM states or
Combinations of <tt>v/z</tt> with <tt>f/F/l</tt> produce two-level Combinations of <tt>v/z</tt> with <tt>f/F/l</tt> produce two-level
views, e.g. <tt>-jp=vf</tt> or <tt>-jp=fv</tt>. This shows the time views, e.g. <tt>-jp=vf</tt> or <tt>-jp=fv</tt>. This shows the time
spent in a VM state or zone vs. hotspots. This can be used to answer spent in a VM state or zone vs. hotspots. This can be used to answer
questions like "Which time consuming functions are only interpreted?" or questions like "Which time-consuming functions are only interpreted?" or
"What's the garbage collector overhead for a specific function?". "What's the garbage collector overhead for a specific function?".
</p> </p>
<p> <p>
@@ -217,7 +215,7 @@ local profile = require("jit.profile")
This module can be used to implement your own higher-level profiler. This module can be used to implement your own higher-level profiler.
A typical profiling run starts the profiler, captures stack dumps in A typical profiling run starts the profiler, captures stack dumps in
the profiler callback, adds them to a hash table to aggregate the number the profiler callback, adds them to a hash table to aggregate the number
of samples, stops the profiler and then analyzes all of the captured of samples, stops the profiler and then analyzes all captured
stack dumps. Other parameters can be sampled in the profiler callback, stack dumps. Other parameters can be sampled in the profiler callback,
too. But it's important not to spend too much time in the callback, too. But it's important not to spend too much time in the callback,
since this may skew the statistics. since this may skew the statistics.
@@ -271,9 +269,9 @@ returns a string with a stack dump for the <tt>thread</tt> (coroutine),
formatted according to the <tt>fmt</tt> argument: formatted according to the <tt>fmt</tt> argument:
</p> </p>
<ul> <ul>
<li><tt>p</tt> &mdash; Preserve the full path for module names. Otherwise <li><tt>p</tt> &mdash; Preserve the full path for module names. Otherwise,
only the file name is used.</li> only the file name is used.</li>
<li><tt>f</tt> &mdash; Dump the function name if it can be derived. Otherwise <li><tt>f</tt> &mdash; Dump the function name if it can be derived. Otherwise,
use module:line.</li> use module:line.</li>
<li><tt>F</tt> &mdash; Ditto, but dump module:name.</li> <li><tt>F</tt> &mdash; Ditto, but dump module:name.</li>
<li><tt>l</tt> &mdash; Dump module:line.</li> <li><tt>l</tt> &mdash; Dump module:line.</li>
@@ -351,7 +349,7 @@ use.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+7 -9
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>Extensions</title> <title>Extensions</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -67,8 +67,6 @@ td.excinterop {
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -88,7 +86,7 @@ or LuaJIT.
</p> </p>
<p> <p>
LuaJIT extends the standard Lua VM with new functionality and adds LuaJIT extends the standard Lua VM with new functionality and adds
several extension modules. Please note this page is only about several extension modules. Please note, this page is only about
<em>functional</em> enhancements and not about performance enhancements, <em>functional</em> enhancements and not about performance enhancements,
such as the optimized VM, the faster interpreter or the JIT compiler. such as the optimized VM, the faster interpreter or the JIT compiler.
</p> </p>
@@ -197,7 +195,7 @@ usage. See also the
</p> </p>
<p> <p>
The generated bytecode is portable and can be loaded on any architecture The generated bytecode is portable and can be loaded on any architecture
that LuaJIT supports, independent of word size or endianess. However the that LuaJIT supports, independent of word size or endianess. However, the
bytecode compatibility versions must match. Bytecode stays compatible bytecode compatibility versions must match. Bytecode stays compatible
for dot releases (x.y.0 &rarr; x.y.1), but may change with major or for dot releases (x.y.0 &rarr; x.y.1), but may change with major or
minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign
@@ -229,7 +227,7 @@ avoids managing backlinks, saves an allocation and the overhead of
incremental array/hash part growth. incremental array/hash part growth.
</p> </p>
<p> <p>
Please note this function is meant for very specific situations. In most Please note, this function is meant for very specific situations. In most
cases it's better to replace the (usually single) link with a new table cases it's better to replace the (usually single) link with a new table
and let the GC do its work. and let the GC do its work.
</p> </p>
@@ -239,7 +237,7 @@ and let the GC do its work.
LuaJIT uses a Tausworthe PRNG with period 2^223 to implement LuaJIT uses a Tausworthe PRNG with period 2^223 to implement
<tt>math.random()</tt> and <tt>math.randomseed()</tt>. The quality of <tt>math.random()</tt> and <tt>math.randomseed()</tt>. The quality of
the PRNG results is much superior compared to the standard Lua the PRNG results is much superior compared to the standard Lua
implementation which uses the platform-specific ANSI rand(). implementation, which uses the platform-specific ANSI rand().
</p> </p>
<p> <p>
The PRNG generates the same sequences from the same seeds on all The PRNG generates the same sequences from the same seeds on all
@@ -257,7 +255,7 @@ Important: Neither this nor any other PRNG based on the simplistic
<h3 id="io"><tt>io.*</tt> functions handle 64&nbsp;bit file offsets</h3> <h3 id="io"><tt>io.*</tt> functions handle 64&nbsp;bit file offsets</h3>
<p> <p>
The file I/O functions in the standard <tt>io.*</tt> library handle The file I/O functions in the standard <tt>io.*</tt> library handle
64&nbsp;bit file offsets. In particular this means it's possible 64&nbsp;bit file offsets. In particular, this means it's possible
to open files larger than 2&nbsp;Gigabytes and to reposition or obtain to open files larger than 2&nbsp;Gigabytes and to reposition or obtain
the current file position for offsets beyond 2&nbsp;GB the current file position for offsets beyond 2&nbsp;GB
(<tt>fp:seek()</tt> method). (<tt>fp:seek()</tt> method).
@@ -464,7 +462,7 @@ C++ destructors.</li>
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+5 -9
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>Frequently Asked Questions (FAQ)</title> <title>Frequently Asked Questions (FAQ)</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -53,8 +53,6 @@ dd { margin-left: 1.5em; }
</li><li> </li><li>
<a class="current" href="faq.html">FAQ</a> <a class="current" href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -65,8 +63,6 @@ dd { margin-left: 1.5em; }
<ul style="padding: 0;"> <ul style="padding: 0;">
<li>The <a href="https://luajit.org/list.html"><span class="ext">&raquo;</span>&nbsp;LuaJIT mailing list</a> focuses on topics <li>The <a href="https://luajit.org/list.html"><span class="ext">&raquo;</span>&nbsp;LuaJIT mailing list</a> focuses on topics
related to LuaJIT.</li> related to LuaJIT.</li>
<li>The <a href="http://wiki.luajit.org/"><span class="ext">&raquo;</span>&nbsp;LuaJIT wiki</a> gathers community
resources about LuaJIT.</li>
<li>News about Lua itself can be found at the <li>News about Lua itself can be found at the
<a href="https://www.lua.org/lua-l.html"><span class="ext">&raquo;</span>&nbsp;Lua mailing list</a>. <a href="https://www.lua.org/lua-l.html"><span class="ext">&raquo;</span>&nbsp;Lua mailing list</a>.
The mailing list archives are worth checking out for older postings The mailing list archives are worth checking out for older postings
@@ -120,7 +116,7 @@ Direct3D version 10 or higher do not show this behavior anymore.
Consider testing your application with older versions, too.<br> Consider testing your application with older versions, too.<br>
Similarly, the Borland/Delphi runtime modifies the FPU control word and Similarly, the Borland/Delphi runtime modifies the FPU control word and
enables FP exceptions. Of course this violates the Windows ABI, too. enables FP exceptions. Of course, this violates the Windows ABI, too.
Please check the Delphi docs for the Set8087CW method.</dd> Please check the Delphi docs for the Set8087CW method.</dd>
</dl> </dl>
@@ -130,7 +126,7 @@ Please check the Delphi docs for the Set8087CW method.</dd>
ignored by compiled code. If your program is running in a tight loop ignored by compiled code. If your program is running in a tight loop
and never falls back to the interpreter, the debug hook never runs and and never falls back to the interpreter, the debug hook never runs and
can't throw the "interrupted!" error.<br> can't throw the "interrupted!" error.<br>
You have to press Ctrl-C twice to get stop your program. That's similar You have to press Ctrl-C twice to stop your program. That's similar
to when it's stuck running inside a C function under the Lua interpreter.</dd> to when it's stuck running inside a C function under the Lua interpreter.</dd>
</dl> </dl>
@@ -150,7 +146,7 @@ so it doesn't rely on the key order. Or sort the table keys, if you must.</dd>
<dl id="sandbox"> <dl id="sandbox">
<dt>Q: Can Lua code be safely sandboxed?</dt> <dt>Q: Can Lua code be safely sandboxed?</dt>
<dd> <dd>
Maybe for an extremly restricted subset of Lua and if you relentlessly Maybe for an extremely restricted subset of Lua and if you relentlessly
scrutinize every single interface function you offer to the untrusted code.<br> scrutinize every single interface function you offer to the untrusted code.<br>
Although Lua provides some sandboxing functionality (<tt>setfenv()</tt>, hooks), Although Lua provides some sandboxing functionality (<tt>setfenv()</tt>, hooks),
@@ -189,7 +185,7 @@ actively developed branches.</dd>
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+243 -96
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>Installation</title> <title>Installation</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -14,25 +14,20 @@ table.compat {
} }
table.compat td { table.compat td {
border: 1px solid #bfcfff; border: 1px solid #bfcfff;
height: 2.5em; height: 1.5em;
} }
table.compat tr.compathead td { table.compat tr.compathead td {
font-weight: bold; font-weight: bold;
border-bottom: 2px solid #bfcfff; border-bottom: 2px solid #bfcfff;
} }
tr.compathead td.compatos { td.compatname, td.compatver {
vertical-align: top; width: 10%;
} }
table.compat td.compatcpu { td.compatbits {
width: 18%; width: 5%;
border-right: 2px solid #bfcfff;
} }
td.compatos { td.compatx {
width: 21%; width: 21%;
vertical-align: middle;
}
td.compatno {
background-color: #d0d0d0;
} }
</style> </style>
</head> </head>
@@ -78,8 +73,6 @@ td.compatno {
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -95,62 +88,204 @@ For the impatient (on POSIX systems):
<pre class="code"> <pre class="code">
make &amp;&amp; sudo make install make &amp;&amp; sudo make install
</pre> </pre>
<h2 id="req">Requirements</h2>
<h3 id="systems">Systems</h3>
<p> <p>
LuaJIT currently builds out-of-the box on most systems. LuaJIT currently builds out-of-the box on most systems:
Here's the compatibility matrix for the supported combinations of
operating systems, CPUs and compilers:
</p> </p>
<table class="compat"> <table class="compat">
<tr class="compathead"> <tr class="compathead">
<td class="compatcpu">CPU / OS</td> <td class="compatname">OS</td>
<td class="compatos"><a href="#posix">Linux</a> or<br><a href="#android">Android</a></td> <td class="compatver">Min. Version</td>
<td class="compatos"><a href="#posix">*BSD, Other</a></td> <td class="compatx">Requirements</td>
<td class="compatos"><a href="#posix">macOS 10.4+</a> or<br><a href="#ios">iOS 3.0+</a></td> <td class="compatx">LuaJIT Versions</td>
<td class="compatos"><a href="#windows">Windows 7<br>or later</a></td>
</tr> </tr>
<tr class="odd separate"> <tr class="odd separate">
<td class="compatcpu">x86 (32 bit)</td> <td class="compatname"><a href="#windows">Windows</a></td>
<td class="compatos">GCC 4.2+</td> <td class="compatver">7</td>
<td class="compatos">GCC 4.2+</td> <td class="compatx">x86 or x64, ARM64: TBA</td>
<td class="compatos">XCode 5.0+<br>Clang</td> <td class="compatx">v2.0 &ndash;</td>
<td class="compatos">MSVC<br>MinGW, Cygwin</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td class="compatcpu">x64 (64 bit)</td> <td class="compatname"><a href="#posix">Linux</a></td>
<td class="compatos">GCC 4.2+</td> <td class="compatver">&nbsp;</td>
<td class="compatos">GCC 4.2+<br>ORBIS (<a href="#ps4">PS4</a>)</td> <td class="compatx">&nbsp;</td>
<td class="compatos">XCode 5.0+<br>Clang</td> <td class="compatx">v2.0 &ndash;</td>
<td class="compatos">MSVC<br>Durango (<a href="#xboxone">Xbox One</a>)</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td> <td class="compatname"><a href="#posix">*BSD</a></td>
<td class="compatos">GCC 4.2+</td> <td class="compatver">&nbsp;</td>
<td class="compatos">GCC 4.2+<br>PSP2 (<a href="#psvita">PS VITA</a>)</td> <td class="compatx">&nbsp;</td>
<td class="compatos">XCode 5.0+<br>Clang</td> <td class="compatx">v2.0 &ndash;</td>
<td class="compatos compatno">&nbsp;</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td class="compatcpu"><a href="#cross2">ARM64<br>ARM64be</a></td> <td class="compatname"><a href="#posix">macOS (OSX)</a></td>
<td class="compatos">GCC 4.8+</td> <td class="compatver">10.4</td>
<td class="compatos compatno">&nbsp;</td> <td class="compatx">&nbsp;</td>
<td class="compatos">XCode 6.0+<br>Clang 3.5+</td> <td class="compatx">v2.1 &ndash;</td>
<td class="compatos compatno">&nbsp;</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td class="compatcpu"><a href="#cross2">PPC</a></td> <td class="compatname"><a href="#posix">POSIX</a></td>
<td class="compatos">GCC 4.3+</td> <td class="compatver">&nbsp;</td>
<td class="compatos">GCC 4.3+<br>GCC 4.1 (<a href="#ps3">PS3</a>)</td> <td class="compatx">mmap, dlopen</td>
<td class="compatos compatno">&nbsp;</td> <td class="compatx">v2.0 &ndash;</td>
<td class="compatos">XEDK (<a href="#xbox360">Xbox 360</a>)</td> </tr>
<tr class="even separate">
<td class="compatname"><a href="#android">Android</a></td>
<td class="compatver">4.0</td>
<td class="compatx">Recent Android NDK</td>
<td class="compatx">v2.0 &ndash;</td>
</tr>
<tr class="odd">
<td class="compatname"><a href="#ios">iOS</a></td>
<td class="compatver">3.0</td>
<td class="compatx">Xcode iOS SDK</td>
<td class="compatx">v2.1 &ndash;</td>
</tr>
<tr class="even separate">
<td class="compatname"><a href="#consoles">PS3</a></td>
<td class="compatver">&nbsp;</td>
<td class="compatx">PS3 SDK</td>
<td class="compatx">v2.0 &ndash; v2.1 EOL</td>
</tr>
<tr class="odd">
<td class="compatname"><a href="#consoles">PS4</a></td>
<td class="compatver">&nbsp;</td>
<td class="compatx">PS4 SDK (ORBIS)</td>
<td class="compatx">v2.0 &ndash;</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td class="compatcpu"><a href="#cross2">MIPS32<br>MIPS64<br>MIPS64r6</a></td> <td class="compatname"><a href="#consoles">PS5</a></td>
<td class="compatos">GCC 4.3+</td> <td class="compatver">&nbsp;</td>
<td class="compatos">GCC 4.3+</td> <td class="compatx">PS5 SDK (PROSPERO)</td>
<td class="compatos compatno">&nbsp;</td> <td class="compatx">v2.1 &ndash;</td>
<td class="compatos compatno">&nbsp;</td> </tr>
<tr class="odd">
<td class="compatname"><a href="#consoles">PS Vita</a></td>
<td class="compatver">&nbsp;</td>
<td class="compatx">PS Vita SDK (PSP2)</td>
<td class="compatx">v2.0 &ndash; v2.1 EOL</td>
</tr>
<tr class="even">
<td class="compatname"><a href="#consoles">Xbox 360</a></td>
<td class="compatver">&nbsp;</td>
<td class="compatx">Xbox 360 SDK (XEDK)</td>
<td class="compatx">v2.0 &ndash; v2.1 EOL</td>
</tr>
<tr class="odd">
<td class="compatname"><a href="#consoles">Xbox One</a></td>
<td class="compatver">&nbsp;</td>
<td class="compatx">Xbox One SDK (DURANGO)</td>
<td class="compatx">v2.1 &ndash;</td>
</tr>
<tr class="even">
<td class="compatname"><a href="#consoles">Nintendo Switch</a></td>
<td class="compatver">&nbsp;</td>
<td class="compatx">NintendoSDK + NX Addon</td>
<td class="compatx">v2.1 &ndash;</td>
</tr> </tr>
</table> </table>
<p>
The codebase has compatibility defines for some more systems, but
without official support.
</p>
<h3 id="toolchains">Toolchains</h3>
<p>
Building LuaJIT requires a recent toolchain based on GCC, Clang/LLVM or
MSVC++.
</p>
<p>
The Makefile-based build system requires GNU Make and supports
cross-builds. Batch files are provided for MSVC++ builds and console
cross-builds.
</p>
<h3 id="architectures">CPU Architectures</h3>
<table class="compat">
<tr class="compathead">
<td class="compatname">CPU</td>
<td class="compatbits">Bits</td>
<td class="compatx">Requirements</td>
<td class="compatx">Variants</td>
<td class="compatx">LuaJIT Versions</td>
</tr>
<tr class="odd separate">
<td class="compatname">x86</td>
<td class="compatbits">32</td>
<td class="compatx">v2.1+: SSE2</td>
<td class="compatx">&nbsp;</td>
<td class="compatx">v2.0 &ndash;</td>
</tr>
<tr class="even">
<td class="compatname">x64</td>
<td class="compatbits">64</td>
<td class="compatx">&nbsp;</td>
<td class="compatx">&nbsp;</td>
<td class="compatx">v2.0 &ndash;</td>
</tr>
<tr class="odd">
<td class="compatname">ARM</td>
<td class="compatbits">32</td>
<td class="compatx">ARMv5+, ARM9E+</td>
<td class="compatx">hard-fp + soft-fp</td>
<td class="compatx">v2.0 &ndash;</td>
</tr>
<tr class="even">
<td class="compatname">ARM64</td>
<td class="compatbits">64</td>
<td class="compatx">&nbsp;</td>
<td class="compatx">ARM64le + ARM64be</td>
<td class="compatx">v2.1 &ndash;</td>
</tr>
<tr class="odd">
<td class="compatname">PPC32</td>
<td class="compatbits">32</td>
<td class="compatx">&nbsp;</td>
<td class="compatx">hard-fp + soft-fp</td>
<td class="compatx">v2.0 &ndash; v2.1 EOL</td>
</tr>
<tr class="even">
<td class="compatname">PPC/e500</td>
<td class="compatbits">32</td>
<td class="compatx">e500v2</td>
<td class="compatx">&nbsp;</td>
<td class="compatx">v2.0 EOL</td>
</tr>
<tr class="odd">
<td class="compatname">MIPS32</td>
<td class="compatbits">32</td>
<td class="compatx">MIPS32r1 &ndash; r5</td>
<td class="compatx">hard-fp + soft-fp</td>
<td class="compatx">v2.0 &ndash;</td>
</tr>
<tr class="even">
<td class="compatname">MIPS64</td>
<td class="compatbits">64</td>
<td class="compatx">MIPS64r1 &ndash; r5</td>
<td class="compatx">hard-fp + soft-fp</td>
<td class="compatx">v2.1 &ndash;</td>
</tr>
<tr class="odd">
<td class="compatname">MIPS64</td>
<td class="compatbits">64</td>
<td class="compatx">MIPS64r6</td>
<td class="compatx">hard-fp + soft-fp</td>
<td class="compatx">v2.1 EOL</td>
</tr>
<tr class="even">
<td class="compatname">RISC-V</td>
<td class="compatbits">64</td>
<td class="compatx">RVA22+</td>
<td class="compatx">&nbsp;</td>
<td class="compatx">TBA</td>
</tr>
</table>
<p>
There are no plans to add historic architectures or to continue support
for end-of-life (EOL) architectures, for which no new CPUs are commonly
available anymore. Likewise, there are no plans to support marginal
and/or de-facto-dead architectures.
</p>
<h2>Configuring LuaJIT</h2> <h2>Configuring LuaJIT</h2>
<p> <p>
@@ -191,7 +326,7 @@ The recommended way to fetch the latest version is to do a pull from
the git repository. the git repository.
</p> </p>
<p> <p>
Alternatively download the latest source package of LuaJIT (pick the .tar.gz). Alternatively, download the latest source package of LuaJIT (pick the .tar.gz).
Move it to a directory of your choice, open a terminal window and change Move it to a directory of your choice, open a terminal window and change
to this directory. Now unpack the archive and change to the newly created to this directory. Now unpack the archive and change to the newly created
directory (replace XX.YY.ZZ with the version you downloaded): directory (replace XX.YY.ZZ with the version you downloaded):
@@ -411,7 +546,7 @@ NDKCROSS=$NDKBIN/aarch64-linux-android-
NDKCC=$NDKBIN/aarch64-linux-android21-clang NDKCC=$NDKBIN/aarch64-linux-android21-clang
make CROSS=$NDKCROSS \ make CROSS=$NDKCROSS \
STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \
TARGET_LD=$NDKCC TARGET_AR=$NDKBIN/llvm-ar TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \
TARGET_STRIP=$NDKBIN/llvm-strip TARGET_STRIP=$NDKBIN/llvm-strip
# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB) # Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB)
@@ -421,7 +556,7 @@ NDKCROSS=$NDKBIN/arm-linux-androideabi-
NDKCC=$NDKBIN/armv7a-linux-androideabi16-clang NDKCC=$NDKBIN/armv7a-linux-androideabi16-clang
make HOST_CC="gcc -m32" CROSS=$NDKCROSS \ make HOST_CC="gcc -m32" CROSS=$NDKCROSS \
STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \
TARGET_LD=$NDKCC TARGET_AR=$NDKBIN/llvm-ar TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \
TARGET_STRIP=$NDKBIN/llvm-strip TARGET_STRIP=$NDKBIN/llvm-strip
</pre> </pre>
<p> <p>
@@ -446,8 +581,7 @@ make DEFAULT_CC=clang CROSS="$(dirname $ICC)/" \
<h3 id="consoles">Cross-compiling for consoles</h3> <h3 id="consoles">Cross-compiling for consoles</h3>
<p> <p>
Building LuaJIT for consoles requires both a supported host compiler Building LuaJIT for consoles requires both a supported host compiler
(x86 or x64) and a cross-compiler (to PPC or ARM) from the official (x86 or x64) and a cross-compiler from the official console SDK.
console SDK.
</p> </p>
<p> <p>
Due to restrictions on consoles, the JIT compiler is disabled and only Due to restrictions on consoles, the JIT compiler is disabled and only
@@ -468,45 +602,58 @@ To cross-compile for <b id="ps3">PS3</b> from a Linux host (requires
make HOST_CC="gcc -m32" CROSS=ppu-lv2- make HOST_CC="gcc -m32" CROSS=ppu-lv2-
</pre> </pre>
<p> <p>
To cross-compile for <b id="ps4">PS4</b> from a Windows host, To cross-compile for the other consoles from a Windows host, open a
open a "Visual Studio .NET Command Prompt" (64&nbsp;bit host compiler), "Native Tools Command Prompt for VS". You need to choose either the 32
<tt>cd</tt> to the directory where you've unpacked the sources and or the 64&nbsp;bit version of the host compiler to match the target.
run the following commands: Then <tt>cd</tt> to the <tt>src</tt> directory below where you've
unpacked the sources and run the build command given in the table:
</p> </p>
<pre class="code"> <table class="compat">
cd src <tr class="compathead">
ps4build <td class="compatname">Console</td>
</pre> <td class="compatbits">Bits</td>
<td class="compatx">Build Command</td>
</tr>
<tr class="odd separate">
<td class="compatname"><b id="ps4">PS4</b></td>
<td class="compatbits">64</td>
<td class="compatx"><tt>ps4build</tt></td>
</tr>
<tr class="even">
<td class="compatname"><b id="ps5">PS5</b></td>
<td class="compatbits">64</td>
<td class="compatx"><tt>ps5build</tt></td>
</tr>
<tr class="odd">
<td class="compatname"><b id="psvita">PS Vita</b></td>
<td class="compatbits">32</td>
<td class="compatx"><tt>psvitabuild</tt></td>
</tr>
<tr class="even">
<td class="compatname"><b id="xbox360">Xbox 360</b></td>
<td class="compatbits">32</td>
<td class="compatx"><tt>xedkbuild</tt></td>
</tr>
<tr class="odd">
<td class="compatname"><b id="xboxone">Xbox One</b></td>
<td class="compatbits">64</td>
<td class="compatx"><tt>xb1build</tt></td>
</tr>
<tr class="even">
<td class="compatname"><b id="nx32">Nintendo Switch NX32</b></td>
<td class="compatbits">32</td>
<td class="compatx"><tt>nxbuild</tt></td>
</tr>
<tr class="odd">
<td class="compatname"><b id="nx64">Nintendo Switch NX64</b></td>
<td class="compatbits">64</td>
<td class="compatx"><tt>nxbuild</tt></td>
</tr>
</table>
<p> <p>
To cross-compile for <b id="psvita">PS Vita</b> from a Windows host, Please check out the comments in the corresponding <tt>*.bat</tt>
open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler), file for more options.
<tt>cd</tt> to the directory where you've unpacked the sources and
run the following commands:
</p> </p>
<pre class="code">
cd src
psvitabuild
</pre>
<p>
To cross-compile for <b id="xbox360">Xbox 360</b> from a Windows host,
open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler),
<tt>cd</tt> to the directory where you've unpacked the sources and run
the following commands:
</p>
<pre class="code">
cd src
xedkbuild
</pre>
<p>
To cross-compile for <b id="xboxone">Xbox One</b> from a Windows host,
open a "Visual Studio .NET Command Prompt" (64&nbsp;bit host compiler),
<tt>cd</tt> to the directory where you've unpacked the sources and run
the following commands:
</p>
<pre class="code">
cd src
xb1build
</pre>
<h2 id="embed">Embedding LuaJIT</h2> <h2 id="embed">Embedding LuaJIT</h2>
<p> <p>
@@ -548,7 +695,7 @@ allocator from your system (no support for this on 64&nbsp;bit architectures).</
of calling <tt>luaopen_base</tt> etc. directly.</li> of calling <tt>luaopen_base</tt> etc. directly.</li>
<li>To change or extend the list of standard libraries to load, copy <li>To change or extend the list of standard libraries to load, copy
<tt>src/lib_init.c</tt> to your project and modify it accordingly. <tt>src/lib_init.c</tt> to your project and modify it accordingly.
Make sure the <tt>jit</tt> library is loaded or the JIT compiler Make sure the <tt>jit</tt> library is loaded, or the JIT compiler
will not be activated.</li> will not be activated.</li>
<li>The <tt>bit.*</tt> module for bitwise operations <li>The <tt>bit.*</tt> module for bitwise operations
is already built-in. There's no need to statically link is already built-in. There's no need to statically link
@@ -567,7 +714,7 @@ in unspeakable ways.
There should be absolutely no need to patch <tt>luaconf.h</tt> or any There should be absolutely no need to patch <tt>luaconf.h</tt> or any
of the Makefiles. And please do not hand-pick files for your packages &mdash; of the Makefiles. And please do not hand-pick files for your packages &mdash;
simply use whatever <tt>make install</tt> creates. There's a reason simply use whatever <tt>make install</tt> creates. There's a reason
for all of the files <em>and</em> directories it creates. for all the files <em>and</em> directories it creates.
</p> </p>
<p> <p>
The build system uses GNU make and auto-detects most settings based on The build system uses GNU make and auto-detects most settings based on
@@ -619,7 +766,7 @@ to me (the upstream) and not you (the package maintainer), anyway.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+4 -6
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>LuaJIT</title> <title>LuaJIT</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -135,8 +135,6 @@ table.feature small {
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -148,7 +146,7 @@ Lua is a powerful, dynamic and light-weight programming language.
It may be embedded or used as a general-purpose, stand-alone language. It may be embedded or used as a general-purpose, stand-alone language.
</p> </p>
<p> <p>
LuaJIT is Copyright &copy; 2005-2021 Mike Pall, released under the LuaJIT is Copyright &copy; 2005-2022 Mike Pall, released under the
<a href="https://www.opensource.org/licenses/mit-license.php"><span class="ext">&raquo;</span>&nbsp;MIT open source license</a>. <a href="https://www.opensource.org/licenses/mit-license.php"><span class="ext">&raquo;</span>&nbsp;MIT open source license</a>.
</p> </p>
<p> <p>
@@ -162,7 +160,7 @@ LuaJIT is Copyright &copy; 2005-2021 Mike Pall, released under the
<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr> <tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr>
</table> </table>
<table class="feature os os3"> <table class="feature os os3">
<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td></tr> <tr><td>PS3</td><td>PS4<br>PS5</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td><td>Nintendo<br>Switch</td></tr>
</table> </table>
<table class="feature compiler"> <table class="feature compiler">
<tr><td>GCC</td><td>Clang<br>LLVM</td><td>MSVC</td></tr> <tr><td>GCC</td><td>Clang<br>LLVM</td><td>MSVC</td></tr>
@@ -222,7 +220,7 @@ Please select a sub-topic in the navigation bar to learn more about LuaJIT.
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>
+13 -6
View File
@@ -3,7 +3,7 @@
<head> <head>
<title>Running LuaJIT</title> <title>Running LuaJIT</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2021"> <meta name="Copyright" content="Copyright (C) 2005-2022">
<meta name="Language" content="en"> <meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
@@ -72,8 +72,6 @@ td.param_default {
</li><li> </li><li>
<a href="faq.html">FAQ</a> <a href="faq.html">FAQ</a>
</li><li> </li><li>
<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
</li><li>
<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a> <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
</li></ul> </li></ul>
</div> </div>
@@ -111,6 +109,7 @@ are accepted:
<li><tt>-t type</tt> &mdash; Set output file type (default: auto-detect from output name).</li> <li><tt>-t type</tt> &mdash; Set output file type (default: auto-detect from output name).</li>
<li><tt>-a arch</tt> &mdash; Override architecture for object files (default: native).</li> <li><tt>-a arch</tt> &mdash; Override architecture for object files (default: native).</li>
<li><tt>-o os</tt> &mdash; Override OS for object files (default: native).</li> <li><tt>-o os</tt> &mdash; Override OS for object files (default: native).</li>
<li><tt>-F name</tt> &mdash; Override filename (default: input filename).</li>
<li><tt>-e chunk</tt> &mdash; Use chunk string as input.</li> <li><tt>-e chunk</tt> &mdash; Use chunk string as input.</li>
<li><tt>-</tt> (a single minus sign) &mdash; Use stdin as input and/or stdout as output.</li> <li><tt>-</tt> (a single minus sign) &mdash; Use stdin as input and/or stdout as output.</li>
</ul> </ul>
@@ -184,7 +183,7 @@ written in Lua. They are mainly used for debugging the JIT compiler
itself. For a description of their options and output format, please itself. For a description of their options and output format, please
read the comment block at the start of their source. read the comment block at the start of their source.
They can be found in the <tt>lib</tt> directory of the source They can be found in the <tt>lib</tt> directory of the source
distribution or installed under the <tt>jit</tt> directory. By default distribution or installed under the <tt>jit</tt> directory. By default,
this is <tt>/usr/local/share/luajit-XX.YY.ZZ>/jit</tt> on POSIX this is <tt>/usr/local/share/luajit-XX.YY.ZZ>/jit</tt> on POSIX
systems (replace XX.YY.ZZ by the installed version). systems (replace XX.YY.ZZ by the installed version).
</p> </p>
@@ -216,11 +215,17 @@ to a specific value.
You can either use this option multiple times (like <tt>-Ocse You can either use this option multiple times (like <tt>-Ocse
-O-dce -Ohotloop=10</tt>) or separate several settings with a comma -O-dce -Ohotloop=10</tt>) or separate several settings with a comma
(like <tt>-O+cse,-dce,hotloop=10</tt>). The settings are applied from (like <tt>-O+cse,-dce,hotloop=10</tt>). The settings are applied from
left to right and later settings override earlier ones. You can freely left to right, and later settings override earlier ones. You can freely
mix the three forms, but note that setting an optimization level mix the three forms, but note that setting an optimization level
overrides all earlier flags. overrides all earlier flags.
</p> </p>
<p> <p>
Note that <tt>-Ofma</tt> is not enabled by default at any level,
because it affects floating-point result accuracy. Only enable this,
if you fully understand the trade-offs of FMA for performance (higher),
determinism (lower) and numerical accuracy (higher).
</p>
<p>
Here are the available flags and at what optimization levels they Here are the available flags and at what optimization levels they
are enabled: are enabled:
</p> </p>
@@ -252,6 +257,8 @@ are enabled:
<td class="flag_name">sink</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Allocation/Store Sinking</td></tr> <td class="flag_name">sink</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Allocation/Store Sinking</td></tr>
<tr class="even"> <tr class="even">
<td class="flag_name">fuse</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Fusion of operands into instructions</td></tr> <td class="flag_name">fuse</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Fusion of operands into instructions</td></tr>
<tr class="odd">
<td class="flag_name">fma </td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_desc">Fused multiply-add</td></tr>
</table> </table>
<p> <p>
Here are the parameters and their default settings: Here are the parameters and their default settings:
@@ -295,7 +302,7 @@ Here are the parameters and their default settings:
</div> </div>
<div id="foot"> <div id="foot">
<hr class="hide"> <hr class="hide">
Copyright &copy; 2005-2021 Copyright &copy; 2005-2022
<span class="noprint"> <span class="noprint">
&middot; &middot;
<a href="contact.html">Contact</a> <a href="contact.html">Contact</a>

Some files were not shown because too many files have changed in this diff Show More