lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have just made the first cut of my POSIX regexp library (which is now just
a front-end to the POSIX functions, and can take advantage of Henry
Spencer's enhanced regexp library to provide matching of nulls).

I have two functions: regex, which takes a pattern and returns the compiled
regex as a userdata, and match, which takes a string and a regex, and
returns match positions as for strfind, and a table of captures.

So far so good. However, both the C functions implementing these have an
upvalue, which is the tag type for my regex userdata. This is the same
method as used in iolib for FILE *s. The problem is that when I'm checking
the arguments to the functions, I can't just check the number of arguments,
because using luaL_check_any to give a nice error message will give a
confusing error message: a call such as

r = regex()  -- wrong! no pattern supplied

will give a message like:

bad argument #2 to match (value expected)

which is confusing, because match only takes one argument. I can't just use
lua_check_any(L, 1) as that will always succeed thanks to the upvalue.

There are other similar considerations when using some other functions from
lauxlib. Is there a good way to fix this?

-- 
http://sc3d.org/rrt/ | maxim, n.  wisdom for fools