X Tutup
Skip to content

Commit 1e23cb4

Browse files
committed
Fixed minor issue, caused by string.gsub returning a pair of values
1 parent c407cae commit 1e23cb4

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

dist/lualib/typescript.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ function TS_indexOf(list, object )
8585
return -1
8686
end
8787

88+
function TS_replace(source, searchVal, newVal)
89+
local result = string.gsub(source, searchVal, newVal)
90+
return result
91+
end
92+
8893
function TS_split(str, separator)
8994
local out = {}
9095

src/Transpiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ export class LuaTranspiler {
953953
const caller = this.transpileExpression(expression.expression);
954954
switch (expression.name.escapedText) {
955955
case "replace":
956-
return `string.gsub(${caller},${params})`;
956+
return `TS_replace(${caller},${params})`;
957957
case "indexOf":
958958
if (node.arguments.length === 1) {
959959
return `(string.find(${caller},${params},1,true) or 0)-1`;

test/unit/string.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export class StringTests {
6262
public replace<T>(inp: string, searchValue: string, replaceValue: string) {
6363
// Transpile
6464
const lua = util.transpileString(
65-
`local res = "${inp}".replace("${searchValue}", "${replaceValue}");
66-
return res;`
65+
`return "${inp}".replace("${searchValue}", "${replaceValue}");`
6766
);
6867

6968
// Execute

0 commit comments

Comments
 (0)
X Tutup