arcticfox1919 / LuaDardo

A Lua virtual machine written in Dart
Apache License 2.0
174 stars 33 forks source link

Unable to embed fennel #25

Open linktohack opened 1 year ago

linktohack commented 1 year ago

Hello,

Thank you for the interesting lib. I'm however unable to embed fennel (https://fennel-lang.org/setup#embedding-the-fennel-compiler-in-a-lua-application.)

I got this error instead

flutter: Err
flutter: >------  stack  top  ------<
flutter: >------ stack bottom ------<
flutter: NoSuchMethodError: Class 'String' has no instance method '-'.
Receiver: "9"
Tried calling: -("0")

This is how I embed fennel:

  void loadLua() async {
    String fennelSrc = await rootBundle.loadString('assets/fennel.lua');
    String src = await rootBundle.loadString('assets/test.lua');
    try {
      LuaState ls = LuaState.newState();
      _ls = ls;
      ls.openLibs();
      FlutterLua.open(ls);
      FlutterWidget.open(ls);
      ls.doString(fennelSrc);
      ls.doString(src);
      setState(() {
        // _ls = ls;
      });
    } catch (e) {
      print("Err");
      _ls?.printStack();
      print(e);
    }
  }

The problems looks like on Dart side, because this works

function getContent1()
    return Row:new({
        children={
            GestureDetector:new({
                onTap=function()
                    flutter.debugPrint("--------------onTap--------------")
                    print("Yay")
                    print(-("0"))
                    flutter.debugPrint("--------------again--------------")
                end,

                child=Text:new("click here")}),
            Text:new("label1"),
            Text:new("label2"),
            Text:new("label3"),
        },
        mainAxisAlign=MainAxisAlign.spaceEvenly,
    })
end

Thanks

arcticfox1919 commented 1 year ago

@linktohack I've skimmed through Fennel, it uses some standard library functions from Lua, but unfortunately, LuaDardo has not implemented the entire standard library of Lua.

linktohack commented 1 year ago

Thanks for the confirmation @arcticfox1919. Is there a way to have a trace if a function is missing?