-
Notifications
You must be signed in to change notification settings - Fork 20
shared
This library handles data sharing between packages. For the high level server and client libraries refer to their own pages.
local shared = require('shared')
✔️ Dependency Not Required
This library does not require an explicit dependency in the
manifest.xml
file for your package.
The shared
table has the following entries:
- shared.new Creates a new shared object
- shared.get Retrieves a shared object
- shared.read Reads shared data from a shared object
- shared.call Calls a function inside a shared environment
- shared.pcall Calls a function inside a shared environment
Creates a new shared object (also called the server since this holds the original data). Note that this value should not be local
, or it may get garbage collected.
function shared.new(name : string) : shared_object
name string
The name of the shared object. Will need this to access it from another package.
The shared object which contains the data and environment information.
Retrieves a shared object from another package (also called the client since it reads the data from the server).
function shared.get(package : string, name : string) : shared_object
package string
The name of the package where to look for the shared object.
name string
The name of the shared object within that package. The same name that was used to create it with
shared.new
.
The shared object which contains the data and environment information.
Reads data from the provided shared object, based on the provided indices.
function shared.read(client : shared_object, ...indices : any) : any
client shared_object
An object retrieved with
shared.get
.
...indices any
Any indices to access the shared data with. If, for example, the shared data contains the following table:
server.data = { recipes = { lasagna = { ingredients = { 'lasagna', }, steps = { 'open packaging', 'put in oven', 'wait 3 hours', 'enjoy', }, }, }, }Then you would access it with
shared.read(client, 'recipes', 'lasagna', 'steps', 4)
and it would result in'enjoy'
.
any
Returns the value inside the server's data store given by successively applying the provided indices.
Calls the provided function with the server's data store as the first argument, followed by the given arguments. This function is executed with the server's env
table as the environment, meaning that only functions defined inside env
will be available to use inside the provided function.
function shared.call(client : shared_object, fn : function, ...args : any) : ...any
client shared_object
An object retrieved with
shared.get
.
fn function
The function to call.
...args any
The arguments to provide to the function.
...any
All results of the function called.
Same as shared.call
but calls the function in protected mode. The first result of the call is a boolean indicating success, followed by either the returned values of the provided function (if successful) or the error message (if not successful)
function shared.call(client : shared_object, fn : function, ...args : any) : boolean, ...any
client shared_object
An object retrieved with
shared.get
.
fn function
The function to call.
...args any
The arguments to provide to the function.
boolean
true
if thepcall
was successful,false
if it failed.
...any
All results of the function called, if the
pcall
was successful, the error message if it failed.
- Background and Architecture
- Windower Data Locations
- Code Standards and Guidelines
- Addon Development
- Windower Commands
- Packet Tutorial
- burdometer
- config
- delay_me_not
- distance
- dress_up
- enternity
- fps
- ime
- logger
- party_time
- paste
- pouches
- send
- shortcuts
- speedometer
- target_info
- terminate
- timestamp
- window_title
- Game
- Windower
- General