2021-10-30 16:01:52 +11:00
## WIP Lua Library
2021-11-16 11:15:59 +11:00
FXServer provides its own system for including files, which we use to load this resource in the fxmanifest via
```lua
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
```lua
local ServerCallback = import 'callbacks'
```
2021-11-11 08:07:33 +11:00
2021-11-25 01:21:22 +11:00
If you don't want to use this resource, but want to reuse code you are permitted to do so under the [license terms ](https://www.gnu.org/licenses/gpl-3.0.html ).
Any resources distributed with this code is subject to the same license restrictions and must be made available under the same license ([more below ](#license )).
2021-11-16 11:15:59 +11:00
#### Currently implemented
- [x] Server callbacks
2021-11-14 02:03:19 +11:00
- [x] Table utilities
2021-11-17 03:37:59 +11:00
- [x] Streaming exports
2021-11-25 01:21:22 +11:00
- [x] SetInterval
2021-11-14 02:03:19 +11:00
2021-11-16 11:15:59 +11:00
#### To do
2021-11-14 02:03:19 +11:00
- Think of more features
- Improvements to import function?
2021-11-16 11:15:59 +11:00
- Improve table utilities (matches only work if the order is the same)
2021-11-14 02:03:19 +11:00
- Transfer non-essential code from ox inventory
2021-11-16 11:15:59 +11:00
- Entity iterators
- Exports for non-runtime critical functions
2021-11-11 08:07:33 +11:00
2021-11-16 11:15:59 +11:00
#### 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.
2021-10-30 16:01:52 +11:00
2021-11-16 11:15:59 +11:00
#### 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
2021-10-30 16:01:52 +11:00
2021-11-16 11:15:59 +11:00
<br>
2021-10-30 16:01:52 +11:00
2021-11-16 11:15:59 +11:00
## Usage
Resources are required to utilise Lua 5.4 to ensure compatibility.
Any scripts must be loaded _ after _ initialising the shared import.
```lua
lua54 'yes'
2021-10-30 16:09:20 +11:00
shared_script '@pe -lualib/init.lua'
2021-10-30 16:01:52 +11:00
```
2021-11-16 11:15:59 +11:00
### ServerCallbacks
- server.lua
```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)
```
2021-10-30 16:01:52 +11:00
- client.lua
```lua
local ServerCallback = import 'callbacks'
2021-11-16 11:15:59 +11:00
-- Trigger the server event and receive a callback function
ServerCallback.Async('resourceName', 'eventName', 100, function(a, b)
print(a, b) -- 'hello there', 'general kenobi'
2021-10-30 16:01:52 +11:00
end, 'hello there')
2021-10-30 16:22:29 +11:00
2021-11-16 11:15:59 +11:00
-- Trigger the server event and await a promise
2021-10-30 16:22:29 +11:00
CreateThread(function()
2021-11-16 11:15:59 +11:00
local a, b = ServerCallback.Await('resourceName', 'eventName', 100, 'hello there')
print(a, b) -- 'hello there', 'general kenobi'
2021-10-30 16:22:29 +11:00
end)
2021-10-30 16:01:52 +11:00
```
2021-11-16 11:15:59 +11:00
<br><h2>License</h2>
<table><tr><td>
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.
2021-10-30 16:09:20 +11:00
2021-11-16 11:15:59 +11:00
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>
</td></tr>
<tr><td>
<font align='center'>https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)</font>
</td></td></table>