https://github.com/04ar/flutter_embed_lua
A Lua binding plugin for Flutter, enabling seamless integration of Lua scripting capabilities within your Flutter applications.
https://github.com/04ar/flutter_embed_lua
embed flutter lua
Last synced: about 1 month ago
JSON representation
A Lua binding plugin for Flutter, enabling seamless integration of Lua scripting capabilities within your Flutter applications.
- Host: GitHub
- URL: https://github.com/04ar/flutter_embed_lua
- Owner: 04AR
- License: bsd-3-clause
- Created: 2025-09-02T14:25:23.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-02T14:27:48.000Z (9 months ago)
- Last Synced: 2025-09-02T19:37:16.253Z (9 months ago)
- Topics: embed, flutter, lua
- Language: Dart
- Homepage:
- Size: 190 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_embed_lua
🚀 **flutter_embed_lua** is a Flutter plugin that embeds a full **Lua runtime** inside your Flutter application. It allows you to **extend your app functionality at runtime** by running Lua scripts, defining custom functions, and bridging Lua with Dart.
---
## ✨ Features
- 🌀 **Run Lua scripts** directly inside your Flutter app.
- 📡 **Call Lua functions from Dart** and vice versa.
- 🔌 **Register custom Dart functions** and expose them to Lua.
- 📦 **Extend runtime behavior** with user-provided scripts.
- 🧩 Optional **extension layer (`LuaExtension`)** for organizing reusable Lua helpers.
---
## 📦 Installation
Add to your `pubspec.yaml`:
```yaml
dependencies:
flutter_embed_lua: latest
```
Then run:
```bash
flutter pub get
```
---
## 📃 Usage
```dart
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_embed_lua/lua_bindings.dart';
import 'package:flutter_embed_lua/lua_runtime.dart';
import 'package:fluttertoast/fluttertoast.dart';
void main() {
// ensure Initialized
WidgetsFlutterBinding.ensureInitialized();
runApp(LuaReplApp());
}
class LuaReplApp extends StatefulWidget {
@override
State createState() => _LuaReplAppState();
}
class _LuaReplAppState extends State {
final LuaRuntime runtime = LuaRuntime();
final TextEditingController controller = TextEditingController();
final List output = [];
final showToastPtr = Pointer.fromFunction)>(
_showToast,
0,
);
static int _showToast(Pointer L) {
final bindings = LuaRuntime.lua;
final msgPtr = bindings.lua_tolstring(L, 1, nullptr);
final msg = msgPtr.cast().toDartString();
Fluttertoast.showToast(
msg: msg,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.TOP,
timeInSecForIosWeb: 1,
backgroundColor: const Color.fromARGB(255, 204, 204, 204),
textColor: const Color.fromARGB(255, 0, 0, 0),
fontSize: 16.0,
);
return 0; // number of return values
}
void runCode() {
final code = controller.text;
final result = runtime.run(code);
setState(() {
output.add("> $code\n$result");
});
controller.clear();
}
@override
void dispose() {
runtime.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
runtime.registerFunction("showToast", showToastPtr);
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("Lua REPL")),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: output.length,
itemBuilder: (context, i) => Padding(
padding: const EdgeInsets.all(4),
child: Text(
output[i],
style: TextStyle(fontFamily: 'monospace'),
),
),
),
),
Row(
children: [
Expanded(
child: TextField(
controller: controller,
onSubmitted: (_) => runCode(),
decoration: InputDecoration(hintText: "Enter Lua code"),
),
),
IconButton(icon: Icon(Icons.send), onPressed: runCode),
],
),
],
),
),
);
}
}
```
---
## 📚 Classes Overview
**LuaRuntime**
**-run(String code)** → Runs Lua code.
**-registerFunction(String name, Function function)** → Exposes a Dart function to Lua.
---
# 🤝 Contributing
Contributions are welcome!
If you’d like to improve this plugin, feel free to open an issue or a pull request