Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lua String with no-inline #11057

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/generators/genlua.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,9 @@ and gen_value ctx e =
gen_expr ctx e
| TMeta (_,e1) ->
gen_value ctx e1
| TCall ({eexpr = (TField (e, (FInstance _ as s)))}, el) when (is_string_expr e) ->
spr ctx ("String.prototype." ^ (field_name s));
gen_paren_arguments ctx (e :: el)
| TCall (e,el) ->
gen_call ctx e el
| TReturn _
Expand Down
14 changes: 7 additions & 7 deletions std/lua/_std/String.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class String {
public inline function toLowerCase():String
return BaseString.lower(this);

public inline function indexOf(str:String, ?startIndex:Int):Int {
public function indexOf(str:String, ?startIndex:Int):Int {
if (startIndex == null)
startIndex = 1;
else
Expand All @@ -86,7 +86,7 @@ class String {
return startIndex > length ? length : startIndex;
}

public inline function lastIndexOf(str:String, ?startIndex:Int):Int {
public function lastIndexOf(str:String, ?startIndex:Int):Int {
var ret = -1;
if (startIndex == null)
startIndex = length;
Expand All @@ -99,11 +99,11 @@ class String {
return ret;
}

public inline function split(delimiter:String):Array<String> {
var idx = 1;
public function split(delimiter:String):Array<String> {
var idx:Null<Int> = 1;
var ret = [];
while (idx != null) {
var newidx = 0;
var newidx:Null<Int> = 0;
if (delimiter.length > 0) {
newidx = BaseString.find(this, delimiter, idx, true).begin;
} else if (idx >= this.length) {
Expand All @@ -128,7 +128,7 @@ class String {
return this;
}

public inline function substring(startIndex:Int, ?endIndex:Int):String {
public function substring(startIndex:Int, ?endIndex:Int):String {
if (endIndex == null)
endIndex = this.length;
if (endIndex < 0)
Expand All @@ -151,7 +151,7 @@ class String {
return BaseString.byte(this, index + 1);
}

public inline function substr(pos:Int, ?len:Int):String {
public function substr(pos:Int, ?len:Int):String {
if (len == null || len > pos + this.length)
len = this.length;
else if (len < 0)
Expand Down
21 changes: 21 additions & 0 deletions tests/misc/lua/projects/Issue9530/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using StringTools;

@:nullSafety(Strict)
class Main {
static var f = "field";
static function main() {
final sclass = new String("foo");
final scl = sclass.toUpperCase();
trace(scl);
final f2 = f.toUpperCase();
trace(f2);
final str = "str".toUpperCase();
trace(str);
final isS = "sss".startsWith("s");
trace(isS);
// test internal static call
final i = "foo".indexOf("");
trace(i);
trace(("dyn" : Dynamic).toUpperCase());
}
}
4 changes: 4 additions & 0 deletions tests/misc/lua/projects/Issue9530/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-main Main
-lua bin/test.lua
--cmd lua bin/test.lua
-D no-inline
6 changes: 6 additions & 0 deletions tests/misc/lua/projects/Issue9530/compile.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Main.hx:9: FOO
Main.hx:11: FIELD
Main.hx:13: STR
Main.hx:15: true
Main.hx:18: 0
Main.hx:19: DYN
3 changes: 2 additions & 1 deletion tests/unit/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{"label": "JavaScript", "args": ["compile-js.hxml", "-cmd", "node -e \"require('./bin/unit.js').unit.TestMain.main()\""]},
{"label": "JVM", "args": ["compile-jvm-only.hxml", "-cmd", "java -jar bin/unit.jar"]},
{"label": "Interp", "args": ["compile-macro.hxml"]},
{"label": "Lua", "args": ["compile-lua.hxml", "-cmd", "lua bin/unit.lua"]},
],
"[haxe]": {
"editor.formatOnSave": true,
Expand All @@ -16,4 +17,4 @@
"arguments": ["-v"]
},
"haxe.enableCompilationServer": false
}
}