knowa_kernel 2.2.0
knowa_kernel: ^2.2.0 copied to clipboard
The runtime that executes Knowa code-push patches inside a Flutter app. Dependency-free. You do not depend on it directly: knowa_sdk does.
example/example.dart
// Runs a small patch on the knowa_kernel runtime.
//
// Patches are normally compiled from Dart source by the Knowa CLI and run by
// knowa_sdk, so an app does not use this package directly. This example builds
// the compiled form of the following patch by hand:
//
// @KnowaOverride('greeting.message')
// String message(String name) => 'Hello, $name!';
import 'package:knowa_kernel/knowa_kernel.dart';
void main() {
const module = KModule(
functions: {
'message': KFunction(
name: 'message',
params: [KParam(0, 'name')],
frameSize: 1,
body: KReturn(KStringInterp([
KLiteral('Hello, '),
KLocalGet(0, 'name'),
KLiteral('!'),
])),
),
},
classes: {},
overrides: {'greeting.message': 'message'},
);
// A patch is delivered in the compact KIR wire format.
final bytes = encodeKirModule(module);
final interpreter = KInterpreter(decodeKirModule(bytes));
print('${bytes.length}-byte patch');
print(interpreter.callOverride('greeting.message', ['Knowa']));
}