starwing / luautf8

a utf-8 support module for Lua and LuaJIT.
MIT License
412 stars 68 forks source link

utf8.remove no arguments doesn't work #12

Closed vadi2 closed 4 years ago

vadi2 commented 7 years ago

utf8.remove(s[, start[, stop]]) -> new_string

delete a substring in s. If neither start nor stop is given, delete the last UTF-8 char in s

> print(utf8.remove("мясо"))
stdin:1: bad argument #2 to 'remove' (number expected, got no value)
stack traceback:
    [C]: in function 'remove'
SDraw commented 7 years ago

Possible typo in readme, because utf8.remove needs second argument https://github.com/starwing/luautf8/blob/master/lutf8lib.c#L497 If replace this line with

luaL_optinteger(L, 2, 1), luaL_optinteger(L, 3, -1)))

it works as intended by readme. If start position should be required argument, then readme should be fixed to point it out.

starwing commented 7 years ago

Good catch! Thanks for report. I'm busy for work recently. But I will look into this as soon as possible.