All pages
Powered by GitBook
1 of 3

Loading...

Loading...

Loading...

SShared

Index

Functions Index

Function

Functions

SetGlobal

void SetGlobal (string ns, string key, DynValue value)

Sets a global key to a value. The value can be any object type.

Parameter
Type
Description

GetGlobal

DynValue GetGlobal (string ns, string key)

Retrieves a previously set global variable, or returns nil.

Parameter
Type
Description

RegisterFunction

void RegisterFunction (string ns, string func, Closure reference)

Makes func into a global function that can be accessed anywhere.

Parameter
Type
Description

RegisterBroadcastFunction

void RegisterBroadcastFunction (string ns, string func, Closure reference)

Makes func into a global function that can be accessed anywhere.

Parameter
Type
Description

UnregisterBroadcastFunction

void UnregisterBroadcastFunction (string ns, string func, Closure reference) void UnregisterBroadcastFunction (string ns, string func)

Unregister Broadcast Function.

Parameter
Type
Description

CallFunction

void CallFunction (string ns, string func, IEnumerable< DynValue > args)

Calls the registered function with the specified arguments.

Parameter
Type
Description

CallBroadcastFunction

int CallBroadcastFunction (string ns, string func, IEnumerable< DynValue > args)

Calls every registered broadcast function with the specified arguments, and returns the number of calls queued.

Parameter
Type
Description

Network

void SetGlobal (string ns, string key, DynValue value)

DynValue GetGlobal (string ns, string key)

void RegisterFunction (string ns, string func, Closure reference)

void RegisterBroadcastFunction (string ns, string func, Closure reference)

void UnregisterBroadcastFunction (string ns, string func, Closure reference) void UnregisterBroadcastFunction (string ns, string func)

void CallFunction (string ns, string func, IEnumerable< DynValue > args)

int CallBroadcastFunction (string ns, string func, IEnumerable< DynValue > args)

Space.Shared.SetGlobal("com.someNameHere.world", "version", "1.02");
local versionValue = Space.Shared.GetGlobal("com.someNameHere.world", "version")
function someFunction(name)
  Space.Log("Hello " .. name);
end

Space.Shared.RegisterFunction("com.someNameHere.world", "func", someFunction);
function someFunction(name)
  Space.Log("Hello " .. name);
end

Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);
example 1
Space.Shared.CallFunction("com.someNameHere.world", "func",{"Smith"});
example 1

SWebservice

Index

Functions Index

Function

Functions

Get

void Get (string url, Closure onComplete, Table headers=null)

Performs an HTTP[S] GET. The callback receives two parameters: success (bool) and response (string).

Parameter
Type
Description

Post

void Post (string url, string data, Closure onComplete, Table headers=null)

Performs an HTTP[S] POST. The callback receives two parameters: success (bool) and response (string).

Parameter
Type
Description

Note:

  • Server requests automatically include: X-Sinespace-Region-ID, X-Sinespace-Instance-ID, X-Sinespace-Script-ID, X-Sinespace-Runtime-Type, and X-Sinespace-In-Editor.

  • There is no timeout parameter on server web requests.

void Get (string url, Closure onComplete, Table headers=null)

void Post (string url, string data, Closure onComplete, Table headers=null)

url

string

The absolute URL to request.

onComplete

Closure

Callback (bool success, string response) invoked on completion.

headers

Table (optional)

Supported keys: Bearer (maps to Authorization: Bearer <token>), Content-Type (rarely used for GET).

url

string

The absolute URL to POST to.

data

string

Request body string. For JSON, send a JSON string and set Content-Type.

onComplete

Closure

Callback (bool success, string response) invoked on completion.

headers

Table (optional)

-- Simple GET
local url = "https://httpbin.org/get"
Space.WebServices.Get(url, function(success, response)
  if success then
    Space.Log("OK: " .. response)
  else
    Space.Log("Request failed: " .. response)
  end
end)

Supported keys: Content-Type (defaults to application/x-www-form-urlencoded), Bearer (maps to Authorization: Bearer <token>).

-- GET with Bearer auth
local url = "https://api.example.com/me"
local headers = { ["Bearer"] = "YOUR_ACCESS_TOKEN" }

Space.WebServices.Get(url, function(success, response)
  if success then
    Space.Log(response)
  else
    Space.Log("Error: " .. response)
  end
end, headers)
-- Form POST
local url = "https://httpbin.org/post"
local body = "x=1&y=2"
Space.WebServices.Post(url, body, function(success, response)
  if success then
    Space.Log("OK: " .. response)
  else
    Space.Log("Error: " .. response)
  end
end)
-- JSON POST with Bearer auth
local url = "https://api.example.com/widgets"
local body = '{"name":"Server Created Widget"}'
local headers = { ["Content-Type"] = "application/json", ["Bearer"] = "YOUR_ACCESS_TOKEN" }

Space.WebServices.Post(url, body, function(success, response)
  if success then
    Space.Log("Created: " .. response)
  else
    Space.Log("Error: " .. response)
  end
end, headers)