arcticfox1919 / LuaDardo

A Lua virtual machine written in Dart
Apache License 2.0
176 stars 34 forks source link

Lua native function cannot be implemented #31

Open snakelet-Ling opened 9 months ago

snakelet-Ling commented 9 months ago

I've tried using string.gsub, string.match neither work, they return the very beginning like nothing is run. I also tried replacing the first parameter with a colon, but it didn't work either.

I would like to ask if there are any Lua functions that can be used in this library?

thauschildt commented 8 months ago

string.gsub is somehow implemented, but full of mistakes. For example if the optional maximum number of replacements is not specified, this is set to -1, resulting in no replacement at all. And the counting of the offsets of the replacements is completeley wrong. Both would probably be not too complicated to fix, but I use my own version (with luaState.register("gsub", myDartGsubVersion) just calling dart's replaceAll function) instead.

You find all available lua functions in lib/src/stdlib/*.dart. Also string.match is there, I didn't check that one for mistakes.

novas1r1 commented 5 months ago

Thanks for opening this issue, I've been wrapping my head around why string.match doesnt work... Does anyone know if this is difficult to implement?

snakelet-Ling commented 4 months ago

string.gsub is somehow implemented, but full of mistakes. For example if the optional maximum number of replacements is not specified, this is set to -1, resulting in no replacement at all. And the counting of the offsets of the replacements is completeley wrong. Both would probably be not too complicated to fix, but I use my own version (with luaState.register("gsub", myDartGsubVersion) just calling dart's replaceAll function) instead.

You find all available lua functions in lib/src/stdlib/*.dart. Also string.match is there, I didn't check that one for mistakes.

Thanks for your answer, I just have time to check it out. I solved this problem using the same method as you...seriously, it's so much easier for me to write my own!

snakelet-Ling commented 4 months ago

Thanks for opening this issue, I've been wrapping my head around why string.match doesnt work... Does anyone know if this is difficult to implement?

Like @thauschildt , the current solution is to write it yourself and then import it into Lua for use. My method is to pre-set a table to call the dart function every time before reading and calling the lua file, and then call it in the lua file as if using lib.

novas1r1 commented 4 months ago

Interesting, I will check it out. Not sure if I got it correct but I will try and let you know.