I wrote this function for debugging purposes, along the lines of assert and error combined, and I'm finding it a great shortcut! You might find some use for it somewhere, or want to include it in the library.

[pascal]{
lua_AssertError(lua_state, condition, error message)
}
function lua_AssertError(L: PLua_State; Condition: Boolean; const Msg: string): boolean;
begin
if condition then
LuaError(L,Msg);
{$IFDEF FPC}
lua_AssertError := condition;
{$ELSEIF}
result := condition;
{$ENDIF}
end;[/pascal]

It's not much really, but it makes structuring things easy! Example:[pascal]function lua_Window(L: PLua_State): integer; cdecl;
begin
if not lua_AssertError(L, lua_gettop(L) <> 4, 'Window() requires four parameters, x1, y1, x2, y2.') then
if not lua_AssertError(L,not (lua_isnumber(L,1) and lua_isnumber(L,2) and
lua_isnumber(L,3) and lua_isnumber(L,4)),'All parameters of Window() must be numbers or numerical strings.') then begin
// Being sneaky here, and cheating a little.
Window(LuaToInteger(L,1),LuaToInteger(L,2),LuaToIn teger(L,3),LuaToInteger(L,4));
end;
lua_Window := 0;
end;[/pascal]

Just remember that it evaluates true on error, shows the message, and then returns true that there was an error. Just in case someone other than us finds use for it. But that simple little thing is saving me debugging time like crazy...

In fact I turned this:[pascal]function lua_GotoXY(L : PLua_State) : integer; cdecl;
var x,y: integer;
begin
lua_GotoXY := 0;


if lua_gettop(L) = 2 then begin
if not lua_AssertError
if lua_isnumber(L,1) then
x := lua_tointeger(L,1)
else
lua_AssertError(L,false, 'Argument 1 in GotoXY() is not a number.');

if lua_isnumber(L,2) then
y := lua_tointeger(L,2)
else
lua_AssertError(L,false, 'Argument 2 in GotoXY() is not a number.');

lua_AssertError(L, (x = 0) and (y = 0), 'Coordinates must be greater than 0.');

GotoXY(x,y);
end else lua_AssertError(L,false, 'Error, GotoXY() requires two arguments of type integer.');
end;[/pascal]
Into this:[pascal]function lua_GotoXY(L : PLua_State) : integer; cdecl;
var x,y: integer;
begin
lua_GotoXY := 0;

if not lua_AssertError(L, lua_gettop(L) <> 2, 'Error, GotoXY() requires two arguments of type integer.') then
if not lua_AssertError(L, not (lua_isnumber(L,1) and lua_isnumber(L,2)), 'GotoXY() requires two number friendly values.') then begin
x := lua_tointeger(L,1)
y := lua_tointeger(L,2)
if not lua_AssertError(L, (x = 0) or (y = 0), 'Coordinates must be greater than 0.') then
GotoXY(x,y);
end;
end;[/pascal]

So much easier to understand.