TypesettingTools / Aegisub

Cross-platform advanced subtitle editor
http://www.aegisub.org
Other
287 stars 479 forks source link

apply karaoke template error #141

Open lyturn opened 2 years ago

lyturn commented 2 years ago

error code:

Runtime error in template code: Expected 1 arguments, got 2 Code producing error: ci = { 0,0 }; cn = _G.unicode.len(orgline.text_stripped:gsub(" ",""))

Yohan050 commented 2 years ago

Add a new pair of parentheses to fix the problem.
Like this: ci = { 0,0 }; cn = _G.unicode.len((orgline.text_stripped:gsub(" ","")))

FichteFoll commented 2 years ago

For an explanation, this is a result of how between Lua 5.1 and 5.2 (with LuaJIT compat mode), if I remember correctly, string.gsub was changed to return multiple values and the default behavior of Lua in such a case is to pass all values as a result to a single-argument function call into the function as arguments. The extra pair of parentheses makes Lua strip all but the first value so that _G.unicode.len only receives one argument.

The0x539 commented 2 years ago

Another option: work in a templater that actually counts character indices for you so that this code that gets copy-pasted everywhere isn't actually necessary.