Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public class LuaNatives {
f.getBody().add(LuaAst.LuaLiteral("local prev = __wurst_enumPlayer_override"));
f.getBody().add(LuaAst.LuaLiteral("ForForce(whichForce, function()"));
f.getBody().add(LuaAst.LuaLiteral(" count = count + 1"));
f.getBody().add(LuaAst.LuaLiteral(" players[count] = __wurst_GetEnumPlayer()"));
f.getBody().add(LuaAst.LuaLiteral(" players[count] = GetEnumPlayer()"));
f.getBody().add(LuaAst.LuaLiteral("end)"));
f.getBody().add(LuaAst.LuaLiteral("for i = 1, count do"));
f.getBody().add(LuaAst.LuaLiteral(" __wurst_enumPlayer_override = players[i]"));
Expand All @@ -206,7 +206,7 @@ public class LuaNatives {
f.getBody().add(LuaAst.LuaLiteral("local prev = __wurst_enumUnit_override"));
f.getBody().add(LuaAst.LuaLiteral("ForGroup(whichGroup, function()"));
f.getBody().add(LuaAst.LuaLiteral(" count = count + 1"));
f.getBody().add(LuaAst.LuaLiteral(" units[count] = __wurst_GetEnumUnit()"));
f.getBody().add(LuaAst.LuaLiteral(" units[count] = GetEnumUnit()"));
f.getBody().add(LuaAst.LuaLiteral("end)"));
f.getBody().add(LuaAst.LuaLiteral("for i = 1, count do"));
f.getBody().add(LuaAst.LuaLiteral(" __wurst_enumUnit_override = units[i]"));
Expand Down Expand Up @@ -234,7 +234,7 @@ public class LuaNatives {
f.getBody().add(LuaAst.LuaLiteral("local prev = __wurst_enumItem_override"));
f.getBody().add(LuaAst.LuaLiteral("EnumItemsInRect(r, filter, function()"));
f.getBody().add(LuaAst.LuaLiteral(" count = count + 1"));
f.getBody().add(LuaAst.LuaLiteral(" items[count] = __wurst_GetEnumItem()"));
f.getBody().add(LuaAst.LuaLiteral(" items[count] = GetEnumItem()"));
f.getBody().add(LuaAst.LuaLiteral("end)"));
f.getBody().add(LuaAst.LuaLiteral("for i = 1, count do"));
f.getBody().add(LuaAst.LuaLiteral(" __wurst_enumItem_override = items[i]"));
Expand Down Expand Up @@ -262,7 +262,7 @@ public class LuaNatives {
f.getBody().add(LuaAst.LuaLiteral("local prev = __wurst_enumDestructable_override"));
f.getBody().add(LuaAst.LuaLiteral("EnumDestructablesInRect(r, filter, function()"));
f.getBody().add(LuaAst.LuaLiteral(" count = count + 1"));
f.getBody().add(LuaAst.LuaLiteral(" dests[count] = __wurst_GetEnumDestructable()"));
f.getBody().add(LuaAst.LuaLiteral(" dests[count] = GetEnumDestructable()"));
f.getBody().add(LuaAst.LuaLiteral("end)"));
f.getBody().add(LuaAst.LuaLiteral("for i = 1, count do"));
f.getBody().add(LuaAst.LuaLiteral(" __wurst_enumDestructable_override = dests[i]"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2762,6 +2762,20 @@ public void luaFunctionRefWrapperForwardsVarargs() throws IOException {
assertFalse(compiled.contains("ForForce(f, function (...) \n\t\t\tlocal tempRes"));
}

@Test
public void forForceCollectorUsesNativeEnumAccessorInLua() throws IOException {
test().testLua(true).withStdLib().lines(
"package Test",
"init",
" let f = CreateForce()",
" ForForce(f, () -> skip)"
);
String compiled = Files.toString(new File("test-output/lua/LuaTranslationTests_forForceCollectorUsesNativeEnumAccessorInLua.lua"), Charsets.UTF_8);
assertTrue(compiled.contains("players[count] = GetEnumPlayer()"));
assertFalse(compiled.contains("players[count] = __wurst_GetEnumPlayer()"));
assertFalse(compiled.contains("function __wurst_GetEnumPlayer("));
}

@Test
public void luaFunctionRefsReuseOneAdapterAndPreserveSingleReturn() {
String compiled = compileLuaWithCUs(
Expand Down Expand Up @@ -2951,6 +2965,12 @@ public void groupItemDestructableCallbacksUseWurstContextHelpersInLua() throws I
assertContainsRegex(compiled, "\\bfunction\\s+__wurst_ForGroup\\s*\\(");
assertContainsRegex(compiled, "\\bfunction\\s+__wurst_EnumItemsInRect\\s*\\(");
assertContainsRegex(compiled, "\\bfunction\\s+__wurst_EnumDestructablesInRect\\s*\\(");
assertTrue(compiled.contains("units[count] = GetEnumUnit()"));
assertTrue(compiled.contains("items[count] = GetEnumItem()"));
assertTrue(compiled.contains("dests[count] = GetEnumDestructable()"));
assertFalse(compiled.contains("units[count] = __wurst_GetEnumUnit()"));
assertFalse(compiled.contains("items[count] = __wurst_GetEnumItem()"));
assertFalse(compiled.contains("dests[count] = __wurst_GetEnumDestructable()"));
}

@Test
Expand Down
Loading