diff --git a/mains/utf8lua.go b/mains/utf8lua.go index 99b5233e..720eb54d 100644 --- a/mains/utf8lua.go +++ b/mains/utf8lua.go @@ -36,5 +36,6 @@ func utf8codes(L *lua.LState) int { func SetupUtf8Table(L *lua.LState) { table := L.NewTable() L.SetField(table, "codes", L.NewFunction(utf8codes)) + L.SetField(table, "charpattern", lua.LString("[\000-\x7F\xC2-\xF4][\x80-\xBF]*")) L.SetGlobal("utf8", table) } diff --git a/t/tst_utf8lib.lua b/t/tst_utf8lib.lua index aedcab94..7731e613 100644 --- a/t/tst_utf8lib.lua +++ b/t/tst_utf8lib.lua @@ -1,4 +1,13 @@ +--- Compare +--- lua_f tst_utf8lib.lua +-- and +--- lua.exe tst_utf8lib.lua | nkf32 + for i,c in utf8.codes("あいうえお") do print(i,c,type(c)) end + +for c in string.gmatch("あいうえお",utf8.charpattern) do + print(c) +end