Aegisub icon indicating copy to clipboard operation
Aegisub copied to clipboard

apply karaoke template error

Open lyturn opened this issue 3 years ago • 3 comments

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(" ",""))

lyturn avatar Sep 26 '21 06:09 lyturn

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

Yohan050 avatar Oct 19 '21 02:10 Yohan050

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.

FichteFoll avatar Oct 19 '21 08:10 FichteFoll

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.

The0x539 avatar Oct 19 '21 15:10 The0x539