lualike 0.0.1-alpha.2 copy "lualike: ^0.0.1-alpha.2" to clipboard
lualike: ^0.0.1-alpha.2 copied to clipboard

A Lua-like scripting language for Dart, designed to be easy to embed and extend. It provides a simple REPL, supports Lua-like syntax, and allows for seamless integration with Dart code.

LuaLike #

GitHub release Pub Version GitHub Actions Workflow Status License issues - lualike

A Lua-like language interpreter implemented in Dart, focusing on a clean, easy-to-use AST-based interpreter.

Features #

  • Lua-like syntax and semantics
  • AST-based interpreter
  • Rich standard library implementation
  • Seamless interoperability with Dart
  • Robust error handling with protected calls

Getting started #

Add the package to your pubspec.yaml:

dependencies:
  lualike: ^0.0.1

Usage #

Basic Usage #

The primary way to execute code is using the AST interpreter.

import 'package:lualike/lualike.dart';

void main() async {
  // Execute some code
  final result = await executeCode('''
    local x = 10
    local y = 20
    return x + y
  ''');

  print('Result: ${result.unwrap()}');
}

Result: 30

Dart Interoperability #

You can easily bridge Dart and LuaLike code using the LuaLike class. The class provides two-way interoperability:

  • expose: Makes Dart functions available to be called from Lua.
  • call: Allows Dart to call functions defined in Lua.
import 'package:lualike/lualike.dart';

void main() async {
  // Create a lualike instance
  final lualike = LuaLike();

  // 1. Expose a Dart function to LuaLike
  lualike.expose('dart_print', (v) {
    print("---------------");
    print(v[0].unwrap());
    print("---------------");
  });

  // 2. Define a Lua function that uses the exposed Dart function
  await lualike.execute('''
    function greet_from_lua(name)
      dart_print("Hello, " .. name .. " from a Dart function!")
    end
  ''');

  // 3. Call the Lua function from Dart
  await lualike.call('greet_from_lua', [Value("World")]);

  // 4. Share data from Dart to Lua
  lualike.setGlobal('config', {'debug': true, 'maxRetries': 3});

  await lualike.execute('''
    if config.debug then
      dart_print("Max retries: " .. config.maxRetries)
    end
  ''');
}

---------------
Hello, World from a Dart function!
---------------
---------------
Max retries: 3
---------------

Documentation #

For more examples, check out the /example folder.

For detailed documentation, see the /docs folder, which includes guides on:

2
likes
140
points
241
downloads

Publisher

verified publisherglenfordwilliams.com

Weekly Downloads

A Lua-like scripting language for Dart, designed to be easy to embed and extend. It provides a simple REPL, supports Lua-like syntax, and allows for seamless integration with Dart code.

Repository (GitHub)
View/report issues

Topics

#lua #scripting #interop #interpreter #repl

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

archive, args, characters, collection, convert, crypto, dart_console, glob, http, logging, path, petitparser, pointycastle, source_span, web, xrandom, yaml

More

Packages that depend on lualike