All tLib Lua exports — menus, dialogs, toasts, themes, logger, HTTP, and permissions.
Lua Exports
All exports are called via exports['tLib']:FunctionName(...).
A full NUI menu system with submenus, item types, and dynamic updates.
Export Description CreateMenu(menuId, title, subtitle, onOpen, onClose, opts)Create a new menu. Returns the resolved menuId. OpenMenu(menuId)Open a menu. CloseMenu(menuId)Close a specific menu. CloseAll()Close all open menus. DeleteMenu(menuId)Remove a menu entirely. ClearMenu(menuId)Remove all items from a menu. CheckMenu(menuId)Returns true if the menu exists. IsOpen()Returns true if any menu is open.
Export Description AddButton(menuId, itemId, label, description, onSelect, opts)Add a button item. AddCheckbox(menuId, itemId, label, description, checked, onToggle, opts)Add a checkbox item. AddSlider(menuId, itemId, label, description, min, max, value, step, onChange, onSelect, opts)Add a slider item. AddList(menuId, itemId, label, description, values, index, onChange, onSelect, opts)Add a list selector item. AddSpacer(menuId, itemId, label, description, opts)Add a non-interactive spacer. AddSubmenuButton(menuId, itemId, submenuId, label, description, onSelect, opts)Add a button that opens a submenu.
Export Description UpdateMenu(menuId, changes)Merge top-level menu fields (title, subtitle, banner, position, size, etc). SetMenuTitle(menuId, title)Update the menu title. SetMenuSubtitle(menuId, subtitle)Update the menu subtitle. SetMenuBanner(menuId, banner)Update the menu banner image. SetMenuLayout(menuId, position, size)Update position and size. RefreshMenu(menuId)Push pending item changes to the UI. Call after batched Add* calls.
Key Type Description positionstring"top-left", "top-center", "bottom-right", etc.sizestring"sm", "md", or "lg"bannerstring|functionURL displayed above the title. blockInputbooleanBlock player movement and camera while open. inheritLayoutbooleanInherit position/size from parent when opened as a submenu. themestringId of a registered tLib theme. itemHeightnumberFixed row height in pixels (default: 40).
local menuId = exports[ 'tLib' ]: CreateMenu ( 'demo' , 'Demo Menu' , 'Pick an option' , nil , nil , {
position = 'top-left' ,
size = 'md' ,
})
exports[ 'tLib' ]: AddButton (menuId, 'greet' , 'Say Hello' , 'Prints a greeting' , function ()
print ( 'Hello!' )
end )
exports[ 'tLib' ]: AddCheckbox (menuId, 'toggle' , 'Toggle Option' , 'On or off' , false , function (checked)
print ( 'Toggled:' , checked)
end )
exports[ 'tLib' ]: AddSlider (menuId, 'vol' , 'Volume' , 'Adjust volume' , 0 , 100 , 50 , 1 , function (val)
print ( 'Volume:' , val)
end )
exports[ 'tLib' ]: RefreshMenu (menuId)
exports[ 'tLib' ]: OpenMenu (menuId)
Modal form dialogs with multiple field types. Results are delivered via events.
Export Description ShowDialog(id, opts)Open a dialog. Returns the resolved dialog id. CloseDialog(id)Close an open dialog (fires the cancelled event).
Key Type Description titlestringDialog heading. descriptionstringOptional subheading. submitLabelstringSubmit button label (default "Submit"). cancelLabelstringCancel button label (default "Cancel"). sizestring"sm", "md", or "lg" (default "md").themestringId of a registered tLib theme. fieldstable[]Array of field definitions.
Type Extra Keys text, number, password, textareaplaceholder, defaultValue, min/max (number only)select, radiooptions ({ value, label }[]), placeholder, defaultValueslidermin, max, step, defaultValuecheckboxdefaultValue (boolean)
All fields share: id (required), type, label, description, required, disabled.
tLib:dialog:opened — (dialogId)
tLib:dialog:submitted — (dialogId, values) — values is a table keyed by field id.
tLib:dialog:cancelled — (dialogId)
local dialogId = exports[ 'tLib' ]: ShowDialog ( 'my_dialog' , {
title = 'Player Info' ,
fields = {
{ id = 'name' , type = 'text' , label = 'Name' , required = true },
{ id = 'age' , type = 'number' , label = 'Age' , min = 1 , max = 120 },
{ id = 'role' , type = 'select' , label = 'Role' , options = {
{ value = 'civ' , label = 'Civilian' },
{ value = 'leo' , label = 'Law Enforcement' },
}},
},
})
AddEventHandler ( 'tLib:dialog:submitted' , function (id, values)
if id == dialogId then
print ( 'Name:' , values. name , 'Age:' , values. age , 'Role:' , values. role )
end
end )
Lightweight toast notifications that stack in the corner of the screen.
Export Description ShowToast(id, toastType, title, description, duration, theme)Show a toast. Returns the resolved id. UpdateToast(id, changes)Update a live toast in place. DismissToast(id)Dismiss a single toast. DismissAll()Dismiss all visible toasts.
Type Default Duration success4000 ms error6000 ms warning5000 ms info4000 ms loadingPersistent (until dismissed or updated)
tLib:toast:shown — (id, toastType, title)
tLib:toast:updated — (id, patch)
tLib:toast:dismissed — (id)
tLib:toast:dismissedAll
-- Simple notification
exports[ 'tLib' ]: ShowToast ( nil , 'success' , 'Saved' , 'Your settings have been saved.' )
-- Loading toast that resolves
local toastId = exports[ 'tLib' ]: ShowToast ( nil , 'loading' , 'Saving...' , 'Please wait.' )
-- Later...
exports[ 'tLib' ]: UpdateToast (toastId, { type = 'success' , title = 'Done' , description = 'Save complete.' })
Register and apply CSS variable-based themes, scoped globally or per-component.
Export Description AddTheme(id, opts)Register a new theme. Returns true on success. RemoveTheme(id)Unregister a theme. Returns true if it existed. SetTheme(id)Apply a theme globally. Pass "" to clear. GetTheme(id)Returns a copy of a theme definition, or nil. GetThemes()Returns all registered themes keyed by id.
Key Type Description namestringHuman-readable display name. descriptionstringOptional description. cssVarstableCSS variable name → value map. Keys must not include the leading --. extendsstringId of another theme to inherit from. fontstringFont-family string (sets --font-sans). fontSizestringBase font-size percentage, e.g. "87.5%".
tLib:theme:added — (id)
tLib:theme:removed — (id)
tLib:theme:set — (id)
Structured console logger with level filtering. Available on both client and server.
Export Description Log(loggerId, args)Format and filter a log line. Returns the formatted string or nil. SetLogLevel(level)Set the global minimum log level (1–4).
Levels: 1 = DEBUG, 2 = INFO, 3 = WARN, 4 = ERROR
local log = function (msg, level)
local line = exports[ 'tLib' ]: Log ( 'myresource' , { msg, level or 2 })
if line then print (line) end
end
log ( 'Server started' ) -- INFO
log ( 'Debug details' , 1 ) -- DEBUG
log ( 'Something went wrong' , 4 ) -- ERROR
Non-blocking HTTP/HTTPS client.
Export Description Fetch(opts, callback)Make an HTTP request.
Key Type Description urlstringFull URL including scheme. Required. methodstringHTTP method (default "GET"). headerstableRequest headers. bodystringRequest body. timeoutnumberTimeout in seconds (default 10). verifybooleanVerify TLS certificate (default false).
Callback: function(err, statusCode, body) — on success err is nil.
exports[ 'tLib' ]: Fetch ({
url = 'https://httpbin.org/get' ,
method = 'GET' ,
}, function (err, status, body)
if err then
print ( 'Error:' , err)
else
print ( 'Status:' , status, 'Body:' , body)
end
end )
HTTPS requires LuaSec. HTTP/2 is not supported.
Admin permission caching with level-based access.
Export Description IsAdmin()Returns true if the player is an admin. GetPermissionLevel()Returns permission level: 0 = none, 1 = admin, 2 = superadmin. RefreshAdminPermission()Refresh the cached admin permission.