jit
Library to work with the LuaJIT functionality of gmod.
Fields
A variable containing the target architecture name: x86, x64, arm, ppc, ppcspe, or mips. This will be x86 or x64 in GMod.
This is NOT a function, it's a variable containing the target OS name: Windows, Linux, OSX, BSD, POSIX or Other.
A variable containing the LuaJIT version string. This is LuaJIT 2. 0. 4 in GMod, and LuaJIT 2. 1. 0-beta3 on the x86-64 branch of GMod.
number jit.version_num
A variable containing the version number of the LuaJIT core.
Methods
You can attach callbacks to a number of compiler events with jit. attach. The callback can be called:
when a function has been compiled to bytecode ("bc");
when trace recording starts or stops ("trace");
as a trace is being recorded ("record");
or when a trace exits through a side exit ("texit").
Set a callback with jit. attach(callback, "event") and clear the same callback with jit. attach(callback)
This function isn't officially documented on LuaJIT wiki, use it at your own risk. Using these constantly (especially bytecode) can be very performance heavy due to the constant stream of data being compiled at a time.
jit.flush()
Flushes the whole cache of compiled code.
jit.off()
Disables LuaJIT Lua compilation.
jit.on()
Enables LuaJIT Lua compilation.
JIT compiler optimization control. The opt sub-module provides the backend for the -O command line LuaJIT option.
You can also use it programmatically, e. g. :
jit. opt. start(2) -- same as -O2
jit. opt. start("-dce")
jit. opt. start("hotloop=10", "hotexit=2")
A list of LuaJIT -O command line options can be found here(a table of various optimization levels are displayed towards the bottom of the page along with exactly which optimization options are enabled for each level): http://luajit. org/running. html
Returns the status of the JIT compiler and the current optimizations enabled.
Returns bytecode of a function at a position.
This function only works for Lua defined functions.
Retrieves LuaJIT information about a given function, similarly to debug. getinfo. Possible table fields:
linedefined: as for debug. getinfo
lastlinedefined: as for debug. getinfo
params: the number of parameters the function takes
stackslots: the number of stack slots the function's local variable use
upvalues: the number of upvalues the function uses
bytecodes: the number of bytecodes it the compiled function
gcconsts: the number of garbage collectable constants
nconsts: the number of lua_Number (double) constants
children: Boolean representing whether the function creates closures
currentline: as for debug. getinfo
isvararg: if the function is a vararg function
source: as for debug. getinfo
loc: a string describing the source and currentline, like "<source>:<line>"
ffid: the fast function id of the function (if it is one). In this case only upvalues above and addr below are valid
addr: the address of the function (if it is not a Lua function). If it's a C function rather than a fast function, only upvalues above is valid*
Gets a constant at a certain index in a function.
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns. This function isn't officially documented on LuaJIT wiki, use it at your own risk. Numbers constants goes from 0 (included) to n-1, n being the value of nconsts in jit. util. funcinfo in other words, the consts goes from (nconsts-1) to -nThis function only works for Lua defined functions.
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns.
Does the exact same thing as debug. getupvalue except it only returns the name, not the name and the object. The upvalue indexes also start at 0 rather than 1, so doing jit. util. funcuvname(func, 0) will get you the same name as debug. getupvalue(func, 1)
This function isn't officially documented on LuaJIT wiki, use it at your own risk.
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns.
Previously got the address of a function from a set list of functions, but now always returns 0 as it is deprecated.
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns. It will always return 0.
Grabs the address of a function based on it's trace exit number. Grabbed via jit. attach (with the texit event).
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns.
Return table fields:
link (number): the linked trace (0 for link types: none, return, interpreter)
nk (number): the lowest IR constant (???)
nins (number): the next IR instruction (???)
linktype (string): the link type (none, root, loop, tail-recursion, up-recursion, down-recursion, interpreter, return)
nexit (number): number of snapshots (for use with jit. util. tracesnap)
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns.
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns.
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns. It will always return 3 0s.
We advise against using this. It may be changed or removed in a future update.
This function was disabled due to security concerns.
Return table fields:
0 (ref) (number): first IR ref for the snapshot
1 (nslots) (number): the number of valid slots
all indexes except first 2 and last (there might not be any of these): the snapshot map
last index in table (number): -16777216 (255 << 24)