Creates a shallow copy of a table or directly returns non-table values.
exports.sonorancad.shallowcopy(data)
Parameter
Type
Description
orig
any
The value or table to copy. Can be of any type: table, string, number, etc.
Type
Description
any
If orig is a table: Returns a new table with the same key-value pairs as orig. If orig is not a table (e.g., a number, string, boolean): Returns the value directly.
-- Example 1: Shallow copying a table
local original = { a = 1, b = 2, c = { 3, 4 } }
local copy = exports.sonorancad.shallowcopy(original)
print(copy.a) -- Output: 1
print(copy.b) -- Output: 2
print(copy.c) -- Output: table: 0x... (same reference as original.c in shallow copy)
-- Example 2: Copying a non-table value
local value = 42
local valueCopy = exports.sonorancad.shallowcopy(value)
print(valueCopy) -- Output: 42
stringsplit
Splits a string into substrings based on a specified delimiter.
exports.sonorancad.stringsplit(inputstr, sep)
Parameter
Type
Description
inputstr
string
The input string that will be split into substrings based on a specified delimiter (sep)
sep
string
(Optional) If not provided, the default is "%s", which matches any whitespace character
Type
Description
table
The table contains the substrings of inputstr split by the delimiter sep. The substrings are stored sequentially starting at index 1
local result = exports.sonorancad.stringsplit("Hello,World,Lua", ",")
-- result = { "Hello", "World", "Lua" }
local result2 = exports.sonorancad.stringsplit("One Two Three")
-- result2 = { "One", "Two", "Three" } (uses default separator: whitespace)
findIndex
Searches for a specific identifier in the LocationCache table and returns the index of the first matching entry.
exports.sonorancad.findIndex(identifier)
Parameter
Type
Description
identifier
any
The identifier to search for, compared against the apiId field of each entry in LocationCache.
Type
Description
number or nil
The index (i) of the first entry in LocationCache whose apiId matches identifier. nil if no matching entry is found
-- Example: Searching for an identifier in LocationCache
LocationCache = {
{ apiId = 101, name = "LocationA" },
{ apiId = 202, name = "LocationB" },
{ apiId = 303, name = "LocationC" },
}
local index = exports.sonorancad.findIndex(202)
print(index) -- Output: 2
local notFound = exports.sonorancad.findIndex(404)
print(notFound) -- Output: nil
GetIdentifiers
Extracts and organizes player identifiers into a key-value table format.
exports.sonorancad.GetIdentifiers(player)
Parameter
Type
Description
player
PlayerSource
The player source ID for whom the identifiers are being retrieved.
Type
Description
table
A key-value table where the keys are identifier types (e.g., steam, license, discord) and the values are the corresponding identifier strings.
The callback function executed when the HTTP request completes.
method
string
The HTTP method to use (e.g., GET, POST, PUT, DELETE).
data
string
(Optional) The data to send with the HTTP request. Defaults to an empty string.
headers
table
(Optional) A table containing custom headers for the HTTP request. Defaults to include X-User-Agent.
Type
Description
none
This function does not directly return a value. Results are handled asynchronously via the cb callback function.
-- Example: Performing a POST request with custom data
local function callback(statusCode, response)
print("Status:", statusCode)
print("Response:", response)
end
exports.sonorancad.PerformHttpRequestS(
"https://api.example.com/data",
callback,
"POST",
'{"key": "value"}',
{ ["Content-Type"] = "application/json" }
)
has_value
Checks if a specific value exists in a table.
exports.sonorancad.has_value(tab, val)
Parameter
Type
Description
tab
table
The table to search for the value.
val
any
The value to search for within the table.
Type
Description
boolean
true if val is found in the table tab. false if val is not found, or if tab is nil.
-- Example 1: Checking if a value exists in a table
local myTable = { "apple", "banana", "cherry" }
local exists = exports.sonorancad.has_value(myTable, "banana")
print(exists) -- Output: true
local notExists = exports.sonorancad.has_value(myTable, "grape")
print(notExists) -- Output: false
-- Example 2: Handling a nil table
local nilTable = nil
local result = exports.sonorancad.has_value(nilTable, "value")
print(result) -- Output: false (with debugLog: "nil passed to has_value, ignore")