-
-
Notifications
You must be signed in to change notification settings - Fork 184
Closed
Labels
Description
tsconfig.json:
{
...
"tstl": {
"luaTarget": "5.1",
"noHeader": true,
"luaLibImport": "inline",
}
}
Example TypeScript:
const testString = "teststring".split("").map((a) => a);
for (const i of testString) {
print(i);
}Generated Lua:
-- Lua Library inline imports
function __TS__StringSubstring(self, start, ____end)
if ____end ~= ____end then
____end = 0
end
if (____end ~= nil) and (start > ____end) then
start, ____end = __TS__Unpack({____end, start})
end
if start >= 0 then
start = start + 1
else
start = 1
end
if (____end ~= nil) and (____end < 0) then
____end = 0
end
return string.sub(self, start, ____end)
end
function __TS__StringSplit(source, separator, limit)
if limit == nil then
limit = 4294967295
end
if limit == 0 then
return {}
end
local out = {}
local index = 0
local count = 0
if (separator == nil) or (separator == "") then
while (index < (#source - 1)) and (count < limit) do
out[count + 1] = __TS__StringAccess(source, index)
count = count + 1
index = index + 1
end
else
local separatorLength = #separator
local nextIndex = (string.find(source, separator, nil, true) or 0) - 1
while (nextIndex >= 0) and (count < limit) do
out[count + 1] = __TS__StringSubstring(source, index, nextIndex)
count = count + 1
index = nextIndex + separatorLength
nextIndex = (string.find(
source,
separator,
math.max(index + 1, 1),
true
) or 0) - 1
end
end
if count < limit then
out[count + 1] = __TS__StringSubstring(source, index)
end
return out
end
function __TS__ArrayMap(arr, callbackfn)
local newArray = {}
do
local i = 0
while i < #arr do
newArray[i + 1] = callbackfn(_G, arr[i + 1], i, arr)
i = i + 1
end
end
return newArray
end
testString = __TS__ArrayMap(
__TS__StringSplit("teststring", ""),
function(____, a) return a end
)
for ____, i in ipairs(testString) do
print(i)
endWhen I run the lua I get an error that __TS__StringAccess is an attempt to call a nil value. The same thing happens for other functions like __TS__Unpack that are also used inside of other __TS library functions. I think what is happening is when it's building the list of library functions it needs to inline, it doesn't bother to check which other library functions they are dependent on, so they may not be included.
Reactions are currently unavailable