opx_lib
Last updated on
A client-only Lua library any resource can require — how to load it, the permission each module needs, and the Result every wrapper answers.
opx_lib is a separate resource. Its wrappers call Open77 natives and answer a Result instead of raising (markers, blips, key bindings, cameras, screen fades, callbacks, raycasts). Its pure helpers cover text, numbers, tables, colours and translations. opx_infinity loads it once on its client and exposes it as OPX.Lib. Version 0.4.0 (Lib.VERSION).
Using it
dependency "opx_lib"
permissions { "world.markers", "input.actions" } -- only what you use, see belowlocal Lib = require('@opx_lib')
local name = Lib.Validate.Word(payload.name, 24)
Lib.Notify.Show('Welcome, ' .. name)| Fact | Detail |
|---|---|
| Client only | The server sandbox has no require, so no server script can load it. To use a pure/ helper on the server, copy the file. |
| Runs in your VM | The code runs inside the resource that calls require. Your permissions, your instruction budget, and every marker, blip, key mapping or callback it creates belongs to you. |
| Permissions | opx_lib declares none: a permission is checked against the calling resource. You declare what you use. A missing one comes back as error = 'permission_denied' with a detail naming the line to add. |
| Per resource | Each resource that requires it gets its own copy of every table. Lib.Locale's catalogue is yours alone. |
Without dependency "opx_lib" | require answers nil, 'module_dependency_not_declared'. |
| Server side | opx_lib's own server script only logs that it is present. |
Manifest helpers
Lib.VERSION
The library version.
Lib.VERSION -- '0.4.0'string
Lib.NEEDS
Each module's NEEDS, read off the modules (Lib.Permission.Of).
Lib.NEEDS -- { Notify = 'ui.vanilla.hud', Input = 'input.actions', ... }table<module, permission>
Lib.Manifest
The permissions { ... } line that covers every module. Print it at start-up to check yours.
Lib.Manifest()Returns
string?—nilwhen nothing is needed
print(Lib.Manifest())Permission per module
| Module | Permission you declare |
|---|---|
Notify | ui.vanilla.hud |
Input | input.actions |
Marker | world.markers (not for Shapes) |
Callback | network.events |
World | world.query |
Blip | ui.vanilla.map |
Camera | camera.script (not for Ray, Owner) |
Screen | screen.effects |
| every other module | none |
Results
Almost every wrapper answers a Result:
{ ok = true, value = v }
{ ok = false, error = code, detail = text }- Common codes from any wrapper:
open77_unavailable,native_not_found(older build),native_raised,permission_denied, or the native's own refusal string. - Validation codes (
invalid_*) are listed per function. - A function marked Yields must run inside
CreateThread.
Modules
Pure modules
No natives and no permission. Same behaviour on any runtime.
Result · Validate · Table · String · Math · Class · Locale · Text · Array · Colour · Permission
Client modules
Wrappers over Open77 natives, client only.
Native · Timer · Character · Notify · Anim · Input · Marker · Callback · Zone · Rpc · Async · World · Players · Blip · Store · Camera · Screen