arcticfox1919 / LuaDardo

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

string.gsub not working #13

Open Z6P0 opened 2 years ago

Z6P0 commented 2 years ago

For example:

chenasraf commented 1 year ago

Can confirm still happens.

The code used to generate this is very basic:

final code = '''
local cmd = "this is a test!"
cmd = string.gsub(cmd, "is", "IS")
Send(cmd)
''';

LuaState state = LuaState.newState();
state.openLibs();
state.pushDartFunction(send);
state.setGlobal("Send");
state.loadString(code);
state.call(0, 0);

// elsewhere

int send(LuaState ls) {
  final cmd = ls.checkString(1) ?? '';
  ls.pop(1);
  debugPrint("lua.Send $cmd");
  store.send(cmd);
  return 0;
}

Here is my output:

ActionSendTo.script: 

local cmd = "this is a test!"
cmd = string.gsub(cmd, "is", "IS")
Send(cmd)

lua.Send this is a test!

The last line should be "this IS a test!"