Skip to content

Commit 9b64723

Browse files
committed
Add simple event handler
1 parent 41c5fde commit 9b64723

File tree

10 files changed

+1018
-57
lines changed

10 files changed

+1018
-57
lines changed

plugin/example/lua.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import 'package:setonix_plugin/setonix_plugin.dart';
2+
import 'package:setonix_plugin/src/rust/frb_generated.dart';
23

4+
const LUA_SCRIPT = '''
5+
print("Hello World")
6+
onEvent("join", function(event)
7+
print("Player joined: " .. event)
8+
end)
9+
''';
310
Future<void> main() async {
4-
await initPluginSystem();
11+
await RustLib.init();
512
final callback = await PluginCallback.default_();
613
await callback.changeOnPrint(
714
onPrint: (p0) {
815
print("printed from sandbox ${p0}");
916
},
1017
);
11-
final luaPlugin = await LuauPlugin(code: '''
12-
print("Hello, World!")
13-
''', callback: callback);
14-
await luaPlugin.run();
18+
final plugin = LuauPlugin(code: LUA_SCRIPT, callback: callback);
19+
await plugin.run();
20+
final eventSystem = await plugin.eventSystem();
21+
await eventSystem.runJoin(name: "Alice");
22+
callback.dispose();
23+
print('end of main');
24+
RustLib.dispose();
1525
}

plugin/flutter_rust_bridge.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
rust_input: rust/src/api/**/*.rs
22
dart_output: lib/src/rust
33
local: true
4+
enable_lifetime: true

plugin/lib/src/rust/api/luau.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@
66
import '../frb_generated.dart';
77
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
88

9-
// These functions are ignored because they are not marked as `pub`: `construct_globals`, `construct_on_print`
9+
// These functions are ignored because they are not marked as `pub`: `construct_event_handler`, `construct_globals`, `construct_globals`, `construct_on_print`, `run_event_handler`
10+
11+
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<Lifetimeable < LuauEventRunner < 'static > >>>
12+
abstract class LuauEventRunner implements RustOpaqueInterface {
13+
Future<void> runJoin({required String name});
14+
}
15+
16+
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<LuauEventSystem>>
17+
abstract class LuauEventSystem implements RustOpaqueInterface {
18+
static Future<LuauEventSystem> default_() =>
19+
RustLib.instance.api.crateApiLuauLuauEventSystemDefault();
20+
}
1021

1122
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<LuauPlugin>>
1223
abstract class LuauPlugin implements RustOpaqueInterface {
24+
LuauEventRunner eventSystem();
25+
1326
factory LuauPlugin(
1427
{required String code, required PluginCallback callback}) =>
1528
RustLib.instance.api

0 commit comments

Comments
 (0)