File: plugin.md

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (89 lines) | stat: -rw-r--r-- 1,966 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Plugin
======

SurgeScript features a plugin system that allows you to extend the functionalities of the language. Known as plugins or [packages](/tutorials/packages), these objects can be imported and accessed anywhere in the code. They are imported using a `using` statement. The plugin system can be accessed simply by typing `Plugin`.

Example:

```
// File: app.ss
// An application that uses StringUtils, defined in another file
using StringUtils;

object "Application"
{
    str = "alucard";

    state "main"
    {
        Console.print("Reverse a string:");
        Console.print(str);
        Console.print(StringUtils.reverse(str));
        Application.exit();
    }
}
```

```
// File: string_utils.ss
// String utilities

@Package
object "StringUtils"
{
    fun reverse(str)
    {
        buf = "";
        for(i = str.length - 1; i >= 0; i--)
            buf += str[i];
        return buf;
    }
}
```

*Available since:* SurgeScript 0.5.2

Properties
----------

#### count

`count`: number, read-only.

The number of plugins.

Functions
---------

#### spawn

`spawn(objectName)`

Spawns an object called `objectName` as a plugin. This function is not to be used directly, as SurgeScript spawns the plugins automatically for you.

*Arguments*

* `objectName`: string. The name of the object to be spawned as a plugin. It's not recommended to include special characters in this name.

#### get

`get(objectName)`

Gets a reference to the plugin named `objectName`. The `[ ]` operator can be used instead of the `get()` function, as in `Plugin[objectName]`.

Rather than using this function, it's recommended to import the desired object using the `using MyObject;` statement at the beginning of your code. Your object will be available as `MyObject`.

*Arguments*

* `objectName`: string. The name of the plugin.

*Example*

```
using StringUtils;

// ...

assert(Plugin["StringUtils"] === StringUtils);
assert(Plugin.StringUtils === StringUtils);
```