Skip to main content

flutter_lua_bridge 0.1.0 copy "flutter_lua_bridge: ^0.1.0" to clipboard
flutter_lua_bridge: ^0.1.0 copied to clipboard

Typed Dart / Lua interoperability with annotation-based code generation.

flutter_lua_bridge #

Run Lua in Flutter and Dart apps with synchronous calls in both directions. Lua is compiled from source for the target platform by a build hook; nothing needs to be installed. LuaRuntime is the single entry point, used directly or through typed APIs generated by flutter_lua_bridge_codegen.

flutter pub add flutter_lua_bridge
import 'package:flutter_lua_bridge/flutter_lua_bridge.dart';

final lua = LuaRuntime.create(); // LuaLibrary.safe by default
try {
  lua['greet'] = lua.function((args) => 'hello ${args.first}');
  print(lua.eval('return greet("lua")')); // hello lua

  final config = lua.eval('return { size = 3, tags = { "a", "b" } }') as LuaTable;
  print(config.toDart()); // {size: 3, tags: [a, b]}
} on LuaBridgeException catch (e) {
  print('${e.message}\n${e.traceback}');
} finally {
  lua.close();
}
  • Values cross the boundary as null, bool, int, double, String, Uint8List, or a handle (LuaTable, LuaFunction, LuaThread, LuaUserdata); Dart Map and List arguments are copied into new tables.
  • Errors never crash the process: every operation runs protected, and a failure is a LuaBridgeException with status, message and traceback.
  • Sandboxing: the default LuaLibrary.safe leaves out io, os, debug and native module loading; other LuaLibrary flags add them. Memory limits and interrupts are available on the runtime.
  • Threading: calls are synchronous and confined to the isolate that created the runtime.

Typed contracts #

Describe the API in Dart and let the generator write both sides:

@LuaApi(module: 'battle')
abstract class BattleApi {
  int calculateDamage(Fighter attacker, Fighter defender);
}

This library re-exports the annotations, so a contract imports only package:flutter_lua_bridge/flutter_lua_bridge.dart. See flutter_lua_bridge_codegen.

Lua version #

Lua 5.3, 5.4 (default) and 5.5 are bundled. Pick one in the workspace root pubspec.yaml:

hooks:
  user_defines:
    flutter_lua_bridge:
      lua_version: "5.5"

A local source tree or a downloaded archive works too; see Choosing the Lua source.

0
likes
0
points
179
downloads

Publisher

verified publishereplab.top

Weekly Downloads

Typed Dart / Lua interoperability with annotation-based code generation.

Repository (GitHub)
View/report issues

Topics

#lua #interop

License

unknown (license)

Dependencies

archive, code_assets, crypto, ffi, flutter_lua_bridge_codegen_annotation, hooks, native_toolchain_c

More

Packages that depend on flutter_lua_bridge