@defold-typescript/types 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-targets.json +1 -1
- package/generated/b2d.d.ts +3 -0
- package/generated/buffer.d.ts +44 -38
- package/generated/builtin-messages.d.ts +1 -1
- package/generated/camera.d.ts +3 -0
- package/generated/collectionfactory.d.ts +47 -40
- package/generated/collectionproxy.d.ts +23 -18
- package/generated/crash.d.ts +3 -0
- package/generated/factory.d.ts +32 -24
- package/generated/go.d.ts +293 -293
- package/generated/graphics.d.ts +3 -0
- package/generated/gui.d.ts +303 -283
- package/generated/http.d.ts +26 -16
- package/generated/iac.d.ts +3 -0
- package/generated/iap.d.ts +6 -3
- package/generated/image.d.ts +30 -26
- package/generated/json.d.ts +36 -32
- package/generated/kinds/gui-script.d.ts +7 -5
- package/generated/kinds/render-script.d.ts +7 -5
- package/generated/kinds/script.d.ts +7 -5
- package/generated/label.d.ts +16 -9
- package/generated/liveupdate.d.ts +29 -26
- package/generated/model.d.ts +57 -45
- package/generated/msg.d.ts +12 -9
- package/generated/particlefx.d.ts +50 -34
- package/generated/physics.d.ts +153 -133
- package/generated/profiler.d.ts +45 -41
- package/generated/push.d.ts +5 -2
- package/generated/render.d.ts +410 -349
- package/generated/resource.d.ts +619 -572
- package/generated/socket.d.ts +49 -33
- package/generated/sound.d.ts +83 -72
- package/generated/sprite.d.ts +36 -32
- package/generated/sys.d.ts +198 -189
- package/generated/tilemap.d.ts +43 -39
- package/generated/timer.d.ts +42 -36
- package/generated/vmath.d.ts +254 -229
- package/generated/webview.d.ts +3 -0
- package/generated/window.d.ts +23 -17
- package/generated/zlib.d.ts +15 -12
- package/index.d.ts +3 -1
- package/package.json +6 -2
- package/scripts/example-store-io.ts +18 -0
- package/scripts/fidelity-audit.ts +61 -1
- package/scripts/fidelity-baseline.json +10 -10
- package/scripts/ref-doc-delta.ts +143 -0
- package/scripts/regen.ts +23 -10
- package/src/core-types.ts +14 -0
- package/src/doc-comment.ts +2 -1
- package/src/emit-dts.ts +238 -18
- package/src/engine-globals.d.ts +2 -0
- package/src/example-store.ts +44 -0
- package/src/go-overloads.d.ts +73 -0
- package/src/index.ts +5 -0
- package/src/lifecycle.ts +157 -16
- package/src/message-dispatch.d.ts +21 -0
- package/src/message-guard.d.ts +19 -0
- package/src/msg-overloads.d.ts +20 -0
- package/src/publish-dts.ts +1 -1
package/generated/sys.d.ts
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import type { Opaque } from "../src/core-types";
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Functions and messages for using system resources, controlling the engine,
|
|
7
|
+
* error handling and debugging.
|
|
8
|
+
*/
|
|
5
9
|
namespace sys {
|
|
6
10
|
/**
|
|
7
11
|
* network connected through other, non cellular, connection
|
|
@@ -21,10 +25,10 @@ declare global {
|
|
|
21
25
|
* @param buffer - buffer to deserialize from
|
|
22
26
|
* @returns lua table with deserialized data
|
|
23
27
|
* @example
|
|
24
|
-
* ```
|
|
25
|
-
* Deserialize a
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Deserialize a table that was previously serialized:
|
|
30
|
+
* const buffer = sys.serialize(my_table);
|
|
31
|
+
* const table = sys.deserialize(buffer);
|
|
28
32
|
* ```
|
|
29
33
|
*/
|
|
30
34
|
function deserialize(buffer: string): Record<string | number, unknown>;
|
|
@@ -35,12 +39,12 @@ declare global {
|
|
|
35
39
|
* @param path - path to check
|
|
36
40
|
* @returns `true` if the path exists, `false` otherwise
|
|
37
41
|
* @example
|
|
38
|
-
* ```
|
|
39
|
-
* Load data but return nil if path didn't exist
|
|
40
|
-
* if
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* return sys.load(path)
|
|
42
|
+
* ```ts
|
|
43
|
+
* // Load data but return nil if path didn't exist
|
|
44
|
+
* if (!sys.exists(path)) {
|
|
45
|
+
* return undefined;
|
|
46
|
+
* }
|
|
47
|
+
* return sys.load(path); // returns {} if it failed
|
|
44
48
|
* ```
|
|
45
49
|
*/
|
|
46
50
|
function exists(path: string): boolean;
|
|
@@ -49,13 +53,16 @@ declare global {
|
|
|
49
53
|
*
|
|
50
54
|
* @param code - exit code to report to the OS, 0 means clean exit
|
|
51
55
|
* @example
|
|
52
|
-
* ```
|
|
53
|
-
* This
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* // This example demonstrates how to exit the application when some kind of quit
|
|
58
|
+
* // message is received (maybe from gui or similar):
|
|
59
|
+
* export default defineScript({
|
|
60
|
+
* on_message(self, message_id, message, sender) {
|
|
61
|
+
* if (message_id === hash("quit")) {
|
|
62
|
+
* sys.exit(0);
|
|
63
|
+
* }
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
59
66
|
* ```
|
|
60
67
|
*/
|
|
61
68
|
function exit(code: number): void;
|
|
@@ -71,28 +78,28 @@ declare global {
|
|
|
71
78
|
* `installed`
|
|
72
79
|
* boolean `true` if the application is installed, `false` otherwise.
|
|
73
80
|
* @example
|
|
74
|
-
* ```
|
|
75
|
-
* Check if twitter is installed:
|
|
76
|
-
* sysinfo = sys.get_sys_info()
|
|
77
|
-
* twitter = {}
|
|
78
|
-
*
|
|
79
|
-
* if sysinfo.system_name
|
|
80
|
-
* twitter = sys.get_application_info("com.twitter.android")
|
|
81
|
-
*
|
|
82
|
-
* twitter = sys.get_application_info("twitter:")
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* if twitter.installed
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* ...
|
|
91
|
-
* <key>LSApplicationQueriesSchemes</key>
|
|
92
|
-
* <array>
|
|
93
|
-
* <string>twitter</string>
|
|
94
|
-
* </array>
|
|
95
|
-
* ...
|
|
81
|
+
* ```ts
|
|
82
|
+
* // Check if twitter is installed:
|
|
83
|
+
* const sysinfo = sys.get_sys_info();
|
|
84
|
+
* let twitter = {};
|
|
85
|
+
*
|
|
86
|
+
* if (sysinfo.system_name === "Android") {
|
|
87
|
+
* twitter = sys.get_application_info("com.twitter.android");
|
|
88
|
+
* } else if (sysinfo.system_name === "iPhone OS") {
|
|
89
|
+
* twitter = sys.get_application_info("twitter:");
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* if (twitter.installed) {
|
|
93
|
+
* // twitter is installed!
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* // Info.plist for the iOS app needs to list the schemes that are queried:
|
|
97
|
+
* // ...
|
|
98
|
+
* // <key>LSApplicationQueriesSchemes</key>
|
|
99
|
+
* // <array>
|
|
100
|
+
* // <string>twitter</string>
|
|
101
|
+
* // </array>
|
|
102
|
+
* // ...
|
|
96
103
|
* ```
|
|
97
104
|
*/
|
|
98
105
|
function get_application_info(app_string: string): { installed: boolean };
|
|
@@ -102,26 +109,26 @@ declare global {
|
|
|
102
109
|
*
|
|
103
110
|
* @returns path to application executable
|
|
104
111
|
* @example
|
|
105
|
-
* ```
|
|
106
|
-
* Find a path where we can store data (the example path is on the macOS platform):
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* print(application_path)
|
|
112
|
+
* ```ts
|
|
113
|
+
* // Find a path where we can store data (the example path is on the macOS platform):
|
|
114
|
+
* // macOS: /Applications/my_game.app
|
|
115
|
+
* const application_path = sys.get_application_path();
|
|
116
|
+
* print(application_path); //> /Applications/my_game.app
|
|
110
117
|
*
|
|
111
|
-
*
|
|
112
|
-
* print(application_path)
|
|
118
|
+
* // Windows: C:\Program Files\my_game\my_game.exe
|
|
119
|
+
* print(application_path); //> C:\Program Files\my_game
|
|
113
120
|
*
|
|
114
|
-
*
|
|
115
|
-
* print(application_path)
|
|
121
|
+
* // Linux: /home/foobar/my_game/my_game
|
|
122
|
+
* print(application_path); //> /home/foobar/my_game
|
|
116
123
|
*
|
|
117
|
-
*
|
|
118
|
-
* print(application_path)
|
|
124
|
+
* // Android package name: com.foobar.my_game
|
|
125
|
+
* print(application_path); //> /data/user/0/com.foobar.my_game
|
|
119
126
|
*
|
|
120
|
-
*
|
|
121
|
-
* print(application_path)
|
|
127
|
+
* // iOS: my_game.app
|
|
128
|
+
* print(application_path); //> /var/containers/Bundle/Applications/123456AB-78CD-90DE-12345678ABCD/my_game.app
|
|
122
129
|
*
|
|
123
|
-
*
|
|
124
|
-
* print(application_path)
|
|
130
|
+
* // HTML5: http://www.foobar.com/my_game/
|
|
131
|
+
* print(application_path); //> http://www.foobar.com/my_game
|
|
125
132
|
* ```
|
|
126
133
|
*/
|
|
127
134
|
function get_application_path(): string;
|
|
@@ -132,9 +139,9 @@ declare global {
|
|
|
132
139
|
* @param default_value - (optional) default value to return if the value does not exist
|
|
133
140
|
* @returns config value as a boolean. default_value if the config key does not exist. false if no default value was supplied.
|
|
134
141
|
* @example
|
|
135
|
-
* ```
|
|
136
|
-
* Get user config value
|
|
137
|
-
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* // Get user config value
|
|
144
|
+
* const vsync = sys.get_config_boolean("display.vsync", false);
|
|
138
145
|
* ```
|
|
139
146
|
*/
|
|
140
147
|
function get_config_boolean(key: string, default_value?: boolean): boolean;
|
|
@@ -145,14 +152,14 @@ declare global {
|
|
|
145
152
|
* @param default_value - (optional) default value to return if the value does not exist
|
|
146
153
|
* @returns config value as an integer. default_value if the config key does not exist. 0 if no default value was supplied.
|
|
147
154
|
* @example
|
|
148
|
-
* ```
|
|
149
|
-
* Get user config value
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* if testmode
|
|
154
|
-
*
|
|
155
|
-
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* // Get user config value
|
|
157
|
+
* const speed = sys.get_config_int("my_game.speed", 20); // with default value
|
|
158
|
+
*
|
|
159
|
+
* const testmode = sys.get_config_int("my_game.testmode"); // without default value
|
|
160
|
+
* if (testmode !== undefined) {
|
|
161
|
+
* // do stuff
|
|
162
|
+
* }
|
|
156
163
|
* ```
|
|
157
164
|
*/
|
|
158
165
|
function get_config_int(key: string, default_value?: number): number;
|
|
@@ -163,9 +170,9 @@ declare global {
|
|
|
163
170
|
* @param default_value - (optional) default value to return if the value does not exist
|
|
164
171
|
* @returns config value as an number. default_value if the config key does not exist. 0 if no default value was supplied.
|
|
165
172
|
* @example
|
|
166
|
-
* ```
|
|
167
|
-
* Get user config value
|
|
168
|
-
*
|
|
173
|
+
* ```ts
|
|
174
|
+
* // Get user config value
|
|
175
|
+
* const speed = sys.get_config_number("my_game.speed", 20.0);
|
|
169
176
|
* ```
|
|
170
177
|
*/
|
|
171
178
|
function get_config_number(key: string, default_value?: number): number;
|
|
@@ -176,15 +183,15 @@ declare global {
|
|
|
176
183
|
* @param default_value - (optional) default value to return if the value does not exist
|
|
177
184
|
* @returns config value as a string. default_value if the config key does not exist. nil if no default value was supplied.
|
|
178
185
|
* @example
|
|
179
|
-
* ```
|
|
180
|
-
* Get user config value
|
|
181
|
-
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* // Get user config value
|
|
188
|
+
* const text = sys.get_config_string("my_game.text", "default text");
|
|
182
189
|
*
|
|
183
|
-
* Start the engine with a bootstrap config override and add a custom config value
|
|
184
|
-
* $ dmengine --config=bootstrap.main_collection=/mytest.collectionc --config=mygame.testmode=1
|
|
190
|
+
* // Start the engine with a bootstrap config override and add a custom config value
|
|
191
|
+
* // $ dmengine --config=bootstrap.main_collection=/mytest.collectionc --config=mygame.testmode=1
|
|
185
192
|
*
|
|
186
|
-
* Read the custom config value from the command line
|
|
187
|
-
*
|
|
193
|
+
* // Read the custom config value from the command line
|
|
194
|
+
* const testmode = sys.get_config_int("mygame.testmode");
|
|
188
195
|
* ```
|
|
189
196
|
*/
|
|
190
197
|
function get_config_string(key: string, default_value?: string): string;
|
|
@@ -198,11 +205,11 @@ declare global {
|
|
|
198
205
|
* - `sys.NETWORK_CONNECTED_CELLULAR` (connected through mobile cellular)
|
|
199
206
|
* - `sys.NETWORK_CONNECTED` (otherwise, Wifi)
|
|
200
207
|
* @example
|
|
201
|
-
* ```
|
|
202
|
-
* Check if we are connected through a cellular connection
|
|
203
|
-
* if (sys.NETWORK_CONNECTED_CELLULAR
|
|
204
|
-
* print("Connected via cellular, avoid downloading big files!")
|
|
205
|
-
*
|
|
208
|
+
* ```ts
|
|
209
|
+
* // Check if we are connected through a cellular connection
|
|
210
|
+
* if (sys.NETWORK_CONNECTED_CELLULAR === sys.get_connectivity()) {
|
|
211
|
+
* print("Connected via cellular, avoid downloading big files!");
|
|
212
|
+
* }
|
|
206
213
|
* ```
|
|
207
214
|
*/
|
|
208
215
|
function get_connectivity(): Opaque<"constant">;
|
|
@@ -217,12 +224,12 @@ declare global {
|
|
|
217
224
|
* `is_debug`
|
|
218
225
|
* boolean If the engine is a debug or release version
|
|
219
226
|
* @example
|
|
220
|
-
* ```
|
|
221
|
-
* How to retrieve engine information:
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* gui.set_text(gui.get_node("version"), version_str)
|
|
227
|
+
* ```ts
|
|
228
|
+
* // How to retrieve engine information:
|
|
229
|
+
* // Update version text label so our testers know what version we're running
|
|
230
|
+
* const engine_info = sys.get_engine_info();
|
|
231
|
+
* const version_str = `Defold ${engine_info.version}\n${engine_info.version_sha1}`;
|
|
232
|
+
* gui.set_text(gui.get_node("version"), version_str);
|
|
226
233
|
* ```
|
|
227
234
|
*/
|
|
228
235
|
function get_engine_info(): { version: string; version_sha1: string; is_debug: boolean };
|
|
@@ -233,14 +240,14 @@ declare global {
|
|
|
233
240
|
* @param filename - file to read from
|
|
234
241
|
* @returns the path prefixed with the proper host mount
|
|
235
242
|
* @example
|
|
236
|
-
* ```
|
|
237
|
-
* Save data on the host
|
|
238
|
-
*
|
|
239
|
-
* sys.save(host_path, mytable)
|
|
240
|
-
*
|
|
241
|
-
* Load data from the host
|
|
242
|
-
*
|
|
243
|
-
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* // Save data on the host
|
|
245
|
+
* const host_path = sys.get_host_path("logs/test.txt");
|
|
246
|
+
* sys.save(host_path, mytable);
|
|
247
|
+
*
|
|
248
|
+
* // Load data from the host
|
|
249
|
+
* const host_path = sys.get_host_path("logs/test.txt");
|
|
250
|
+
* const table = sys.load(host_path);
|
|
244
251
|
* ```
|
|
245
252
|
*/
|
|
246
253
|
function get_host_path(filename: string): string;
|
|
@@ -259,14 +266,14 @@ declare global {
|
|
|
259
266
|
* `running`
|
|
260
267
|
* boolean `true` if the interface is running, `false` otherwise.
|
|
261
268
|
* @example
|
|
262
|
-
* ```
|
|
263
|
-
* How to get the IP address of interface "en0":
|
|
264
|
-
* ifaddrs = sys.get_ifaddrs()
|
|
265
|
-
* for
|
|
266
|
-
* if
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
269
|
+
* ```ts
|
|
270
|
+
* // How to get the IP address of interface "en0":
|
|
271
|
+
* const ifaddrs = sys.get_ifaddrs();
|
|
272
|
+
* for (const iface of ifaddrs) {
|
|
273
|
+
* if (iface.name === "en0") {
|
|
274
|
+
* const ip = iface.address;
|
|
275
|
+
* }
|
|
276
|
+
* }
|
|
270
277
|
* ```
|
|
271
278
|
*/
|
|
272
279
|
function get_ifaddrs(): { name: string; address: string; mac: string; up: boolean; running: boolean }[];
|
|
@@ -278,27 +285,27 @@ declare global {
|
|
|
278
285
|
* @param file_name - file-name to get path for
|
|
279
286
|
* @returns path to save-file
|
|
280
287
|
* @example
|
|
281
|
-
* ```
|
|
282
|
-
* Find a path where we can store data:
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
* print(my_file_path)
|
|
288
|
+
* ```ts
|
|
289
|
+
* // Find a path where we can store data:
|
|
290
|
+
* const my_file_path = sys.get_save_file("my_game", "my_file");
|
|
291
|
+
* // macOS: /Users/foobar/Library/Application Support/my_game/my_file
|
|
292
|
+
* print(my_file_path); //> /Users/foobar/Library/Application Support/my_game/my_file
|
|
286
293
|
*
|
|
287
|
-
*
|
|
288
|
-
* print(my_file_path)
|
|
294
|
+
* // Windows: C:\Users\foobar\AppData\Roaming\my_game\my_file
|
|
295
|
+
* print(my_file_path); //> C:\Users\foobar\AppData\Roaming\my_game\my_file
|
|
289
296
|
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* print(my_file_path)
|
|
297
|
+
* // Linux: $XDG_DATA_HOME/my_game/my_file or /home/foobar/.my_game/my_file
|
|
298
|
+
* // Linux: Defaults to /home/foobar/.local/share/my_game/my_file if neither exist.
|
|
299
|
+
* print(my_file_path); //> /home/foobar/.local/share/my_game/my_file
|
|
293
300
|
*
|
|
294
|
-
*
|
|
295
|
-
* print(my_file_path)
|
|
301
|
+
* // Android package name: com.foobar.packagename
|
|
302
|
+
* print(my_file_path); //> /data/data/0/com.foobar.packagename/files/my_file
|
|
296
303
|
*
|
|
297
|
-
*
|
|
298
|
-
* print(my_file_path)
|
|
304
|
+
* // iOS: my_game.app
|
|
305
|
+
* print(my_file_path); //> /var/mobile/Containers/Data/Application/123456AB-78CD-90DE-12345678ABCD/my_game/my_file
|
|
299
306
|
*
|
|
300
|
-
*
|
|
301
|
-
* print(my_file_path)
|
|
307
|
+
* // HTML5 path inside the IndexedDB: /data/.my_game/my_file or /.my_game/my_file
|
|
308
|
+
* print(my_file_path); //> /data/.my_game/my_file
|
|
302
309
|
* ```
|
|
303
310
|
*/
|
|
304
311
|
function get_save_file(application_id: string, file_name: string): string;
|
|
@@ -331,12 +338,12 @@ declare global {
|
|
|
331
338
|
* `user_agent`
|
|
332
339
|
* string The HTTP user agent, i.e. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"
|
|
333
340
|
* @example
|
|
334
|
-
* ```
|
|
335
|
-
* How to get system information:
|
|
336
|
-
*
|
|
337
|
-
* if info.system_name
|
|
338
|
-
*
|
|
339
|
-
*
|
|
341
|
+
* ```ts
|
|
342
|
+
* // How to get system information:
|
|
343
|
+
* const info = sys.get_sys_info();
|
|
344
|
+
* if (info.system_name === "HTML5") {
|
|
345
|
+
* // We are running in a browser.
|
|
346
|
+
* }
|
|
340
347
|
* ```
|
|
341
348
|
*/
|
|
342
349
|
function get_sys_info(options?: { ignore_secure?: boolean }): { device_model: string; manufacturer: string; system_name: string; system_version: string; api_version: string; language: string; device_language: string; territory: string; gmt_offset: number; device_ident: string; user_agent: string };
|
|
@@ -347,13 +354,13 @@ declare global {
|
|
|
347
354
|
* @param filename - file to read from
|
|
348
355
|
* @returns lua table, which is empty if the file could not be found
|
|
349
356
|
* @example
|
|
350
|
-
* ```
|
|
351
|
-
* Load data that was previously saved, e.g. an earlier game session:
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* if
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
+
* ```ts
|
|
358
|
+
* // Load data that was previously saved, e.g. an earlier game session:
|
|
359
|
+
* const my_file_path = sys.get_save_file("my_game", "my_file");
|
|
360
|
+
* const my_table = sys.load(my_file_path);
|
|
361
|
+
* if (!next(my_table)) {
|
|
362
|
+
* // empty table
|
|
363
|
+
* }
|
|
357
364
|
* ```
|
|
358
365
|
*/
|
|
359
366
|
function load(filename: string): Record<string | number, unknown>;
|
|
@@ -370,16 +377,16 @@ declare global {
|
|
|
370
377
|
*
|
|
371
378
|
* @param filename - resource to load, full path
|
|
372
379
|
* @example
|
|
373
|
-
* ```
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
* if data
|
|
378
|
-
*
|
|
379
|
-
* pprint(data_table)
|
|
380
|
-
* else
|
|
381
|
-
* print(error)
|
|
382
|
-
*
|
|
380
|
+
* ```ts
|
|
381
|
+
* // Load level data into a string
|
|
382
|
+
* const [data, error] = sys.load_resource("/assets/level_data.json");
|
|
383
|
+
* // Decode json string to a table
|
|
384
|
+
* if (data) {
|
|
385
|
+
* const data_table = json.decode(data);
|
|
386
|
+
* pprint(data_table);
|
|
387
|
+
* } else {
|
|
388
|
+
* print(error);
|
|
389
|
+
* }
|
|
383
390
|
* ```
|
|
384
391
|
*/
|
|
385
392
|
function load_resource(filename: string): LuaMultiReturn<[string | unknown, string | unknown]>;
|
|
@@ -397,12 +404,12 @@ declare global {
|
|
|
397
404
|
* - `name` - The name of the window (Note: the name does not specify the title of the new window).
|
|
398
405
|
* @returns a boolean indicating if the url could be opened or not
|
|
399
406
|
* @example
|
|
400
|
-
* ```
|
|
401
|
-
* Open an URL:
|
|
402
|
-
*
|
|
403
|
-
* if
|
|
404
|
-
*
|
|
405
|
-
*
|
|
407
|
+
* ```ts
|
|
408
|
+
* // Open an URL:
|
|
409
|
+
* const success = sys.open_url("http://www.defold.com", { target: "_blank" });
|
|
410
|
+
* if (!success) {
|
|
411
|
+
* // could not open the url...
|
|
412
|
+
* }
|
|
406
413
|
* ```
|
|
407
414
|
*/
|
|
408
415
|
function open_url(url: string, attributes?: { target?: string }): boolean;
|
|
@@ -420,11 +427,11 @@ declare global {
|
|
|
420
427
|
* @param arg5 - argument 5
|
|
421
428
|
* @param arg6 - argument 6
|
|
422
429
|
* @example
|
|
423
|
-
* ```
|
|
424
|
-
* How to reboot engine with a specific bootstrap collection.
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
* sys.reboot(arg1, arg2)
|
|
430
|
+
* ```ts
|
|
431
|
+
* // How to reboot engine with a specific bootstrap collection.
|
|
432
|
+
* const arg1 = "--config=bootstrap.main_collection=/my.collectionc";
|
|
433
|
+
* const arg2 = "build/game.projectc";
|
|
434
|
+
* sys.reboot(arg1, arg2);
|
|
428
435
|
* ```
|
|
429
436
|
*/
|
|
430
437
|
function reboot(arg1?: string, arg2?: string, arg3?: string, arg4?: string, arg5?: string, arg6?: string): void;
|
|
@@ -442,12 +449,12 @@ declare global {
|
|
|
442
449
|
* @param filename - file to write to
|
|
443
450
|
* @param table - lua table to save
|
|
444
451
|
* @example
|
|
445
|
-
* ```
|
|
446
|
-
* Save data:
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
* sys.save(my_file_path, my_table)
|
|
452
|
+
* ```ts
|
|
453
|
+
* // Save data:
|
|
454
|
+
* const my_table = [];
|
|
455
|
+
* my_table.push("my_value");
|
|
456
|
+
* const my_file_path = sys.get_save_file("my_game", "my_file");
|
|
457
|
+
* sys.save(my_file_path, my_table);
|
|
451
458
|
* ```
|
|
452
459
|
*/
|
|
453
460
|
function save(filename: string, table: Record<string | number, unknown>): void;
|
|
@@ -459,11 +466,11 @@ declare global {
|
|
|
459
466
|
* @param table - lua table to serialize
|
|
460
467
|
* @returns serialized data buffer
|
|
461
468
|
* @example
|
|
462
|
-
* ```
|
|
463
|
-
* Serialize table:
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
469
|
+
* ```ts
|
|
470
|
+
* // Serialize table:
|
|
471
|
+
* const my_table = [];
|
|
472
|
+
* my_table.push("my_value");
|
|
473
|
+
* const buffer = sys.serialize(my_table);
|
|
467
474
|
* ```
|
|
468
475
|
*/
|
|
469
476
|
function serialize(table: Record<string | number, unknown>): string;
|
|
@@ -472,8 +479,8 @@ declare global {
|
|
|
472
479
|
*
|
|
473
480
|
* @param host - hostname to check against
|
|
474
481
|
* @example
|
|
475
|
-
* ```
|
|
476
|
-
* sys.set_connectivity_host("www.google.com")
|
|
482
|
+
* ```ts
|
|
483
|
+
* sys.set_connectivity_host("www.google.com");
|
|
477
484
|
* ```
|
|
478
485
|
*/
|
|
479
486
|
function set_connectivity_host(host: string): void;
|
|
@@ -489,24 +496,26 @@ declare global {
|
|
|
489
496
|
* `traceback`
|
|
490
497
|
* string The stack traceback.
|
|
491
498
|
* @example
|
|
492
|
-
* ```
|
|
493
|
-
* Install error handler that just prints the errors
|
|
494
|
-
*
|
|
495
|
-
* print(source)
|
|
496
|
-
* print(message)
|
|
497
|
-
* print(traceback)
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
* return 10 + "string"
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
499
|
+
* ```ts
|
|
500
|
+
* // Install error handler that just prints the errors
|
|
501
|
+
* function my_error_handler(source, message, traceback) {
|
|
502
|
+
* print(source); //> lua
|
|
503
|
+
* print(message); //> main/my.script:10: attempt to perform arithmetic on a string value
|
|
504
|
+
* print(traceback); //> stack traceback:
|
|
505
|
+
* //> main/test.script:10: in function 'boom'
|
|
506
|
+
* //> main/test.script:15: in function <main/my.script:13>
|
|
507
|
+
* }
|
|
508
|
+
*
|
|
509
|
+
* function boom() {
|
|
510
|
+
* return 10 + "string";
|
|
511
|
+
* }
|
|
512
|
+
*
|
|
513
|
+
* export default defineScript({
|
|
514
|
+
* init() {
|
|
515
|
+
* sys.set_error_handler(my_error_handler);
|
|
516
|
+
* boom();
|
|
517
|
+
* },
|
|
518
|
+
* });
|
|
510
519
|
* ```
|
|
511
520
|
*/
|
|
512
521
|
function set_error_handler(error_handler: (source: unknown, message: unknown, traceback: unknown) => void): void;
|
|
@@ -519,9 +528,9 @@ declare global {
|
|
|
519
528
|
*
|
|
520
529
|
* @param frequency - target frequency. 60 for 60 fps
|
|
521
530
|
* @example
|
|
522
|
-
* ```
|
|
523
|
-
* Setting the update frequency to 60 frames per second
|
|
524
|
-
* sys.set_update_frequency(60)
|
|
531
|
+
* ```ts
|
|
532
|
+
* // Setting the update frequency to 60 frames per second
|
|
533
|
+
* sys.set_update_frequency(60);
|
|
525
534
|
* ```
|
|
526
535
|
*/
|
|
527
536
|
function set_update_frequency(frequency: number): void;
|
|
@@ -538,9 +547,9 @@ declare global {
|
|
|
538
547
|
*
|
|
539
548
|
* @param swap_interval - target swap interval.
|
|
540
549
|
* @example
|
|
541
|
-
* ```
|
|
542
|
-
* Setting the swap intervall to swap every v-blank
|
|
543
|
-
* sys.set_vsync_swap_interval(1)
|
|
550
|
+
* ```ts
|
|
551
|
+
* // Setting the swap intervall to swap every v-blank
|
|
552
|
+
* sys.set_vsync_swap_interval(1);
|
|
544
553
|
* ```
|
|
545
554
|
*/
|
|
546
555
|
function set_vsync_swap_interval(swap_interval: number): void;
|