Linden 4d51879afd refactor(init): metatables and micro-optimise
import now stores all imported modules and uses call and index methods to load modules.

Defining an import as before (local ServerCallbacks = import 'callbacks') works as before, or you can use ServerCallbacks = import.callbacks

You could also use a lazy loading method by never defining ServerCallbacks, i.e. import.callbacks.Register(...) will work without explicitly importing the module previously.
2021-11-28 18:04:09 +11:00
2021-11-16 11:15:59 +11:00
2021-11-25 01:21:22 +11:00
2021-11-16 19:37:36 +11:00

WIP Lua Library

FXServer provides its own system for including files, which we use to load this resource in the fxmanifest via

shared_script '@pe-lualib/init.lua'

Once loaded, any resource can use simple in-line declarations to load anything from the imports folder, i.e

local ServerCallback = import 'callbacks'

If you don't want to use this resource, but want to reuse code you are permitted to do so under the license terms.
Any resources distributed with this code is subject to the same license restrictions and must be made available under the same license (more below).

Currently implemented

  • Server callbacks
  • Table utilities
  • OxMySQL wrapper (might scrap for oxmysql v2.0.0)
  • Streaming exports
  • Metatable packing/unpacking
  • SetInterval

To do

  • Think of more features
  • Improvements to import function?
  • Improve table utilities (matches only work if the order is the same)
  • Transfer non-essential code from ox inventory
  • Entity iterators
  • Exports for non-runtime critical functions

Native wrappers

Likely to be handled as exports rather than imports, handling things such as entity creation, blips, markers, etc.
Anything that is capable of OneSync RPC's is prioritised over direct client functions.

Compatibility wrappers

Setup imports for ESX and QBCore compatibility with certain tables, functions, and events; this should only be for important framework features, i.e

  • PlayerData / xPlayer / QBPlayer
  • GetPlayers / GetExtendedPlayers / GetQBPlayers

Usage

Resources are required to utilise Lua 5.4 to ensure compatibility.
Any scripts must be loaded after initialising the shared import.

lua54 'yes'
shared_script '@pe-lualib/init.lua'

ServerCallbacks

  • server.lua
local ServerCallback = import 'callbacks'

-- Registers a server event with the name __cb_resourceName:eventName
ServerCallback.Register('eventName', function(source, cb, data)
    cb(data, 'general kenobi')
end)
  • client.lua
local ServerCallback = import 'callbacks'

-- Trigger the server event and receive a callback function
ServerCallback.Async('resourceName', 'eventName', 100, function(a, b)
    print(a, b) -- 'hello there', 'general kenobi'
end, 'hello there')

-- Trigger the server event and await a promise
CreateThread(function()
    local a, b = ServerCallback.Await('resourceName', 'eventName', 100, 'hello there')
    print(a, b) -- 'hello there', 'general kenobi'
end)


License

pe-lualib

Copyright (C) 2021 Linden https://www.github.com/thelindat

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see https://www.gnu.org/licenses/gpl-3.0.html

https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)
Description
No description provided
Readme 5.7 MiB
Languages
Lua 62.5%
TypeScript 35.6%
CSS 1.7%