global lua
😱 Types incomplete or incorrect? 🙏 Please contribute!
methods
lua.setbytecode
Save a function in a bytecode register.
Example:
lua.setbytecode(13, function () print('A message') end)
local print_message = lua.getbytecode(13)
print_message() -- 'A message'
Reference:
- Corresponding C source code: llualib.c#L249-L315
lua.getbytecode
Return a previously stored function from a bytecode register.
Example:
lua.setbytecode(13, function () print('A message') end)
local print_message = lua.getbytecode(13)
print_message() -- 'A message'
Reference:
- Corresponding C source code: llualib.c#L187-L212
lua.getcodepage
@return - command handler
@return - graphical user interface
😱 Types incomplete or incorrect? 🙏 Please contribute!
Return two numbers, one for the command handler and one for the graphical user interface (on Microsoft Windows).
Reference:
- Corresponding C source code: llualib.c#L382-L392
lua.setluaname
@param
chunk_name
- If you want to unset a Lua name, you can assign nil
to it.
Set a Lua chunk name.
When a chunk name starts with
a @
it will be displayed as a file name. This is a side effect of the way Lua implements error
handling.
Reference:
- Corresponding C source code: llualib.c#L318-L339-
@see lua.name lua.getluaname
lua.getluaname
Return a Lua chunk name.
Reference:
- Corresponding C source code: llualib.c#L341-L354
@see lua.name lua.setluaname
lua.newtable
Create a new empty table and push it onto the stack.
Parameter index
is a hint for how many elements the table will have as a sequence; parameter hash
is a hint for how many other elements the table will have. Lua may use these hints to preallocate memory for the new table. This preallocation is useful for performance when you know in advance how many elements the table will have.
Reference:
- Corresponding C source code: llualib.c#L362-L368
- lua_createtable
lua.getstacktop
Return a number indicating how much nesting is going on.
It is only of use as a breakpoint when checking some mechanism going haywire.
Reference:
LuaTeX
manual: 10.1.4 Introspection- Corresponding C source code: llualib.c#L370-L374
lua.getcalllevel
Return a number indicating how much nesting is going on.
It is only of use as a breakpoint when checking some mechanism going haywire.
Reference:
- Corresponding C source code: llualib.c#L376-L380
LuaTeX
manual: 10.1.4 Introspection
lua.get_functions_table
The \directlua
commands involves tokenization of its argument (after
picking up an optional name or number specification). The tokenlist is then
converted into a string and given to Lua to turn into a function that is
called. The overhead is rather small but when you have millions of calls it can
have some impact. For this reason there is a variant call available: \luafunction
. This command is used as follows:
\directlua {
local t = lua.get_functions_table()
t[1] = function() tex.print("!") end
t[2] = function() tex.print("?") end
}
\luafunction1
\luafunction2
Of course the functions can also be defined in a separate file. There is no limit
on the number of functions apart from normal Lua limitations. Of course there
is the limitation of no arguments but that would involve parsing and thereby give
no gain. The function, when called in fact gets one argument, being the index, so
in the following example the number 8
gets typeset.
This creates a token that refers to a Lua function with an entry in the table
that you can access with lua.get_functions_table
. It is the companion
to luadef
.
Reference:
LuaTeX
manual: 2.4.4\luafunction
,\luafunctioncall
and\luadef
LuaTeX
manual: 10.6.4 Macros- Corresponding C source code: llualib.c#L356-L360
fields
lua.version
Version information: This library contains one read-only item:
This returns the Lua version identifier string.
Reference:
- Corresponding C source code: llualib.c#L416-L417
lua.bytecode
Use the bytecode
table to store Lua code chunks. The accepted values for
assignments are functions and nil
. Likewise, the retrieved value is
either a function or nil
.
The contents of the lua.bytecode
array is stored inside the format file
as actual Lua bytecode, so it can also be used to preload Lua code. The
function must not contain any upvalues.
lua.name
There is an array of 65536 (0-65535) potential chunk names for use with the
directlua
and latelua
primitives.
@see lua.getluaname lua.setluaname