ElunaLuaEngine/Eluna — pull request #97 by Patman64 (2014-08-02 07:54:28+00:00)
Title: CHECKVAL cleanup

Essentially I made the version of CHECKVAL with a default argument completely generic rather than needing a specialization for each type, since I noticed essentially the same code being duplicated in each specialization.

Other changes:
- `luaL_checkunsigned` and `luaL_checkint` are not used since `unsigned` and `int` are only guaranteed to be at least 2 bytes wide, not 4. `luaL_checklong` is used instead for all integer conversions.
- When the wrong type is supplied to an optional argument, an error will be thrown instead of using the default value. (The idea: *When given a choice between doing something potentially unwanted or throwing an error, it is better to throw an error.*)
- Along the same lines, when a value is too large for what it is being cast to, an error will be thrown instead of silently overflowing. Ranges for parameters will be specified in the documentation.
- The `bool` version of CHECKVAL has been significantly reduced. It should work in the exact same manner.
- In the `int64` and `uint64` versions of CHECKVAL, the return value of `sscanf` is checked to make sure that the GUID was converted without a problem.
- Since the `lua_isnoneornil` function is used in LuaEngine.h, I moved the lua.h include to LuaEngine.h.

Known issues:
- **When a negative value is used where an `uint32` is expected** it will be converted to a large `uint32` value. There is no way to tell when a large value or negative value is intended so this cannot be caught.