# SShared

**成员** 7

|      |                                                             |                                                                                                                 |
| ---- | ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| 函数 | [SetGlobal](#setglobal)                                     | Sets a global key to a value.                                                                                   |
| 函数 | [GetGlobal](#getglobal)                                     | Retrieves a previously set global variable, or returns nil.                                                     |
| 函数 | [RegisterFunction](#registerfunction)                       | Makes func into a global function that can be accessed anywhere.                                                |
| 函数 | [RegisterBroadcastFunction](#registerbroadcastfunction)     | Makes func into a global function that can be accessed anywhere.                                                |
| 函数 | [UnregisterBroadcastFunction](#unregisterbroadcastfunction) | Unregister Broadcast Function.                                                                                  |
| 函数 | [CallFunction](#callfunction)                               | Calls the registered function with the specified arguments.                                                     |
| 函数 | [CallBroadcastFunction](#callbroadcastfunction)             | Calls every registered broadcast function with the specified arguments, and returns the number of calls queued. |

## 函数

### SetGlobal

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

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

参数

| 名称  | 类型     | 默认值 |
| ----- | -------- | ------ |
| ns    | string   | –      |
| key   | string   | –      |
| value | DynValue | –      |

返回值

`void`

示例

**Lua**

```lua
Space.Shared.SetGlobal("com.someNameHere.world", "version", "1.02");

```

### GetGlobal

DynValue GetGlobal(string ns, string key)

Retrieves a previously set global variable, or returns nil.

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| ns   | string | –      |
| key  | string | –      |

返回值

`DynValue`

示例

**Lua**

```lua
local versionValue = Space.Shared.GetGlobal("com.someNameHere.world", "version")

```

### RegisterFunction

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

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

参数

| 名称      | 类型    | 默认值 |
| --------- | ------- | ------ |
| ns        | string  | –      |
| func      | string  | –      |
| reference | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function someFunction(name)
  Space.Log("Hello " .. name);
end

Space.Shared.RegisterFunction("com.someNameHere.world", "func", someFunction);

```

### RegisterBroadcastFunction

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

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

参数

| 名称      | 类型    | 默认值 |
| --------- | ------- | ------ |
| ns        | string  | –      |
| func      | string  | –      |
| reference | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function someFunction(name)
  Space.Log("Hello " .. name);
end

Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);

```

### UnregisterBroadcastFunction

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

void UnregisterBroadcastFunction(string ns, string func)

Unregister Broadcast Function.

参数

| 名称      | 类型    | 默认值 |
| --------- | ------- | ------ |
| ns        | string  | –      |
| func      | string  | –      |
| reference | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
example 1

```

### CallFunction

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

Calls the registered function with the specified arguments.

参数

| 名称 | 类型                    | 默认值 |
| ---- | ----------------------- | ------ |
| ns   | string                  | –      |
| func | string                  | –      |
| args | IEnumerable< DynValue > | –      |

返回值

`void`

示例

**Lua**

```lua
Space.Shared.CallFunction("com.someNameHere.world", "func",{"Smith"});

```

### 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.

参数

| 名称 | 类型                    | 默认值 |
| ---- | ----------------------- | ------ |
| ns   | string                  | –      |
| func | string                  | –      |
| args | IEnumerable< DynValue > | –      |

返回值

`int`

示例

**Lua**

```lua
example 1

```
