Uh, Jeremy? I just tried compiling a sandbox, and it gave me about 48 errors in FPC 2.0.4 saying that "result is undefined". Did I leave something out?
luaexec.pas:
Code:
program luaexec;
{$MODE DELPHI}
uses LuaWrapper, lua, LuaUtils, SysUtils, crt;
function lua_Search(L : PLua_State) : integer; cdecl;
var
i, n, idx : integer;
searchResult : TSearchRec;
path, mask: AnsiString; // You should always use AnsiStrings and not Strings
begin
n := lua_gettop(L); // Get the number of items being passed in
if n > 0 then
begin
path := luatostring(L, 1);
if n > 1 then
mask := luatostring(L, 2)
else
mask := '*.*';
end
else
begin
mask := '*.*';
path := ExtractFilePath(ParamStr(0));
end;
lua_newtable(L); // Create a new table
idx := lua_tointeger(L, 1);
lua_Search := 1;
i := 1;
if FindFirst(path + mask, faAnyFile, searchResult) = 0 then
begin
repeat
lua_pushinteger(L, i);
inc(i);
luapushstring(path + mask);
lua_settable(L, idx);
until FindNext(searchResult) <> 0;
FindClose(searchResult);
end;
end;
function lua_KeyPressed(L : PLua_State) : integer; cdecl;
begin
luapushboolean(L,KeyPressed);
end;
var main: TLua;
BEGIN
main := TLua.Create(nil);
main.LoadFile('main.lua');
main.RegisterMethod('FindFiles', @lua_Search);
main.RegisterMethod('KeyPressed', @lua_KeyPressed);
main.Execute;
main.free;
END.
main.lua:
Code:
-- MAIN.LUA
print("Greetings Terran!");
while not KeyPressed() do end
Should work according to what I know. FPC has always seemed picky to me though, so I never quite understood the problem with things like this. I thought result was always assumed in a function.
Errors raised:
Code:
lua.pas(796,3) Error: Identifier not found "result"
lua.pas(814,3) Error: Identifier not found "result"
lua.pas(840,3) Error: Identifier not found "result"
lua.pas(845,3) Error: Identifier not found "result"
lua.pas(850,3) Error: Identifier not found "result"
lua.pas(855,3) Error: Identifier not found "result"
lua.pas(860,3) Error: Identifier not found "result"
lua.pas(865,3) Error: Identifier not found "result"
lua.pas(870,3) Error: Identifier not found "result"
lua.pas(875,3) Error: Identifier not found "result"
lua.pas(880,3) Error: Identifier not found "result"
lua.pas(900,3) Error: Identifier not found "result"
lua.pas(905,3) Error: Identifier not found "result"
lua.pas(915,3) Error: Identifier not found "result"
lua.pas(934,3) Error: Identifier not found "result"
lua.pas(946,5) Error: Identifier not found "result"
lua.pas(948,5) Error: Identifier not found "result"
lua.pas(953,3) Error: Identifier not found "result"
lua.pas(958,3) Error: Identifier not found "result"
lua.pas(963,3) Error: Identifier not found "result"
lua.pas(968,3) Error: Identifier not found "result"
lua.pas(973,3) Error: Identifier not found "result"
lua.pas(978,3) Error: Identifier not found "result"
lua.pas(983,3) Error: Identifier not found "result"
lua.pas(988,3) Error: Identifier not found "result"
lua.pas(989,6) Error: Identifier not found "result"
lua.pas(990,5) Error: Identifier not found "result"
lua.pas(995,3) Error: Identifier not found "result"
lua.pas(996,6) Error: Identifier not found "result"
lua.pas(997,5) Error: Identifier not found "result"
lua.pas(1026,5) Error: Identifier not found "result"
lua.pas(1030,5) Error: Identifier not found "result"
lua.pas(1073) Fatal: There were 32 errors compiling module, stopping
lua.pas(5,46) Fatal: Compilation aborted
Bookmarks