flutter_lualike 0.2.1
flutter_lualike: ^0.2.1 copied to clipboard
Flutter integration for lualike. Provides AssetBundle filesystem backend, build hook for compiling Lua scripts, and convenience APIs for running Lua in Flutter apps.
flutter_lualike #
Flutter integration for lualike.
This package gives you two things:
- A Flutter asset-bundle filesystem backend for
require(),dofile(), andio.open(). - A hooks re-export so Flutter projects can write build hooks without
depending on
lualike_hooksdirectly.
What it solves #
Use flutter_lualike when you want Lua scripts to live inside a Flutter app,
loaded from assets, while still using the same lualike runtime on Dart and
Flutter.
Install #
dependencies:
flutter_lualike:
path: path/to/flutter_lualike
Runtime setup #
Configure lualike to read from Flutter assets:
import 'package:flutter/services.dart';
import 'package:flutter_lualike/flutter_lualike.dart';
await useAssetBundle(rootBundle, assetRoot: 'build/lua');
After that, require('hello') and dofile('script.lua') resolve from the
asset bundle.
Build hooks #
flutter_lualike re-exports lualike_hooks, so your hook/build.dart can be:
import 'package:hooks/hooks.dart';
import 'package:flutter_lualike/hooks.dart';
void main(List<String> args) async {
await build(args, (input, output) async {
final builder = LuaBuilder(
sources: ['assets/lua/'],
mode: CompileMode.bytecode,
);
await builder.run(input: input, output: output, logger: null);
});
}
Asset layout #
A typical Flutter project looks like this:
my_app/
assets/
lua/
hello.lua
hook/
build.dart
lib/
main.dart
pubspec.yaml
And pubspec.yaml should include the compiled output:
flutter:
assets:
- build/lua/
Modes #
The re-exported hooks API supports:
CompileMode.bytecode-- compile to bytecode files inbuild/lua/CompileMode.dartSource-- generate Dart source filesCompileMode.dartEmbed-- generate Dart files with embedded bytecode bytes
Example #
See example/ for a full Flutter app using flutter_lualike
with hooks and runtime execution.