PureDartLua
This is a custom a custom Lua 5.5 interpretter and evaluator written from scratch in pure Dart.
I wrote this as a part of a series of learning exercises on how to write my own compilers and programming languages.
Run Scripts
This package exports a full fledged library and a simple executable for running lua scripts.
To get started, run Hello World.
dart bin/main.dart -e test/assets/hello_world.lua
Features
- MIT Licensed.
- Register your own custom runtime userdata.
- No FFI or extra dependencies.
- Emit warnings, diagnostic info, or errors.
- Lua 5.5 compliant.
- See this section for remaining issues.
- Parser, Evaluator, Interpreter classes you can extend or modify.
TruthyandNative2LuaDart class extensions.- Makes for convenient bridge between userdata and lua types.
- Standard lua runtime libs (partial implementation).
- strings
- include
- ipairs
- pairs
- table
- math
- Autodoc API so your own libs can generate docs to share with your consumers.
- Function builder API to conveniently build complex lua functions.
Because this is a pure dart lua interpreter, it is not expected to be as fast as the C ffi alternative libs for Dart. However, it is much more programmer friendly!
Work In Progress!
I am using this in my own projects and as such I have not created tutorials or get started guides. I will get around to that when I can!
Missing Lua Lang Support
Here's what's left to be compliant with the Lua 5.5 specification:
- Missing a semantics pass for
gotoand::label::statements. - Metamethods.
- Particularly there is no support for metamethods except for
___call. - But metamethods are just function objects with a few places that lua calls as defined.
- Particularly there is no support for metamethods except for
<const>is not added.- Coroutines are not added.
- I may have missed one variant of function declarations.
Extra Goals
- Semantics: code path type unification.
returnstatements could have the function's final type identified.- Nondeterministic functions should be identified as such.
- This would allow invariant code paths to be protomoted to constant value generation.
Libraries
- docs/autodoc
- docs/prism
- These contents were generated by Prism. https://prismjs.com/download.html#themes=prism-tomorrow&languages=lua
- lua/lua
- lua/passes/colorize
- lua/passes/lexer
- lua/passes/parser
- lua/visitors/bindings/std
- lua/visitors/pretty
- lua/visitors/runtime/base
- lua/visitors/runtime/luaobject
- lua/visitors/runtime/scope
- lua/visitors/runtime/semantics
- lua/visitors/visitor
- utils