This repository was archived by the owner on Feb 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +84
-1814
lines changed Expand file tree Collapse file tree 7 files changed +84
-1814
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ #include "actrwasm.h"
2
+ #include "actrfetch.h"
3
+ #include "actrmap.h"
4
+ #include "actrcanvas.h"
5
+ #include "actrasync.h"
6
+ #include "actrjson.h"
7
+
8
+ // fetch json example
9
+
10
+ int asyncHandle = 0 ;
11
+ char * text = "loading will begin shortly..." ;
12
+
13
+ [[clang ::export_name ("actr_async_result" )]]
14
+ void actr_async_result (int handle , int success )
15
+ {
16
+ if (handle == asyncHandle ) {
17
+ if (success == 1 ) {
18
+ text = actr_json_get_string (1 , "MyObject.one" );
19
+ } else {
20
+ // this will happen if the fetch request fails
21
+ asyncHandle = 0 ;
22
+ text = "fetch error, retrying..." ;
23
+ }
24
+ }
25
+ }
26
+
27
+ [[clang ::export_name ("actr_step" )]]
28
+ void actr_step (double delta )
29
+ {
30
+ if (asyncHandle == 0 )
31
+ {
32
+ text = "loading..." ;
33
+ asyncHandle = actr_fetch_json ("https://mrnathanstiles.github.io/test.json" , 1 );
34
+ if (asyncHandle < 1 ) {
35
+ // this would happen if the url is invalid or rejected
36
+ // this will happen if actr_async_result is not exported
37
+ text = "url error, retrying..." ;
38
+ asyncHandle = 0 ;
39
+ }
40
+ }
41
+
42
+
43
+ actr_canvas2d_fillStyle (0 , 0 , 0 , 100 );
44
+ actr_canvas2d_fillRect (-10 , -10 , 9999 , 9999 );
45
+
46
+ actr_canvas2d_fillStyle (255 , 255 , 255 , 100 );
47
+ actr_canvas2d_fillText (10 , 20 , text , strlen (text ));
48
+
49
+ }
Original file line number Diff line number Diff line change
1
+ #include "actrwasm.h"
2
+
1
3
#ifndef ACTRJSON_H
2
4
#define ACTRJSON_H
5
+
6
+ int actr_json_get_int_length (int jsonId , char * path , int pathLength );
7
+ float actr_json_get_float_length (int jsonId , char * path , int pathLength );
8
+ char * actr_json_get_string_length (int jsonId , char * path , int pathLength );
9
+
10
+ int actr_json_get_int (int jsonId , char * path ) {
11
+ return actr_json_get_int_length (jsonId , path , strlen (path ));
12
+ }
13
+ float actr_json_get_float (int jsonId , char * path ) {
14
+ return actr_json_get_float_length (jsonId , path , strlen (path ));
15
+ }
16
+ char * actr_json_get_string (int jsonId , char * path ) {
17
+ return actr_json_get_string_length (jsonId , path , strlen (path ));
18
+ }
19
+
3
20
#endif
4
21
Original file line number Diff line number Diff line change 1
1
@ echo off
2
+
2
3
clear
4
+
3
5
SET script = %1
4
6
SET server = %2
5
7
6
-
7
8
if " %script% " == " " (
8
9
echo Example use
9
10
echo ./pub.bat scriptFile.c
10
11
exit
11
12
)
12
13
13
- if " %script% " == " script.c" (
14
- SET apiKey = pmu58grtf9vbyyxsy0ozr1l78wr1otlg4vaz7o1xpcz8amfd3x
15
- )
16
-
17
14
if " %script% " == " fetch-text.c" (
18
15
SET apiKey = pjy2drrc8hhhvk9gx7c8ga3h3aa6l4en9rtk5sa8rbisgz0hpd
19
16
)
20
-
17
+
18
+ if " %script% " == " fetch-json.c" (
19
+ SET apiKey = w3pwm3k3bzdj9jskjzo8c5axm5ffd8ygz51tzgi6q9jgp98jjj
20
+ )
21
+
21
22
if " %script% " == " myScript" (
22
23
SET apiKey = myApiKey
23
24
)
24
25
25
26
if " %apiKey% " == " " (
26
- echo apiKey not assigned for file
27
+ echo apiKey not assigned for file
28
+ exit
29
+ )
30
+
31
+ if %server% == local (
32
+ SET server = https://localhost:7086/api/Wasm/Upload/
33
+ ) else (
34
+ SET server = https://www.d1ag0n.com/api/Wasm/Upload/
27
35
)
28
36
29
37
echo Building...
38
+
30
39
clang %script% -I header --target=wasm32-unknown-unknown ^
31
40
--optimize=3 -nostdlib -nostdlibinc -nostdinc -nostdinc++ ^
32
41
-Wl,--no-entry -Wl,--export-all -Wl,--error-limit=0 ^
33
42
-Wl,--allow-undefined --wasm-opt --output %script% .wasm
34
43
35
- if %server% == local (
36
- SET server = https://localhost:7086/api/Wasm/Upload/
37
- echo SET LOCAL %server%
38
- ) else (
39
- SET server = https://www.d1ag0n.com/api/Wasm/Upload/
40
- echo SET REMOTE %server%
41
- )
42
- echo %server%
44
+
43
45
44
46
if %ERRORLEVEL% == 0 (
45
- echo Build success uploading...
46
-
47
+ echo Uploading...
47
48
curl -k -F " data=@./%script% .wasm" " %server%%apiKey% %"
48
49
) else (
49
50
echo Build failed
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments