Commit 8ab94ab9 authored by Mark van Renswoude's avatar Mark van Renswoude

Changed: Call renamed to Run

Added: Call methods to call a named Lua function
parent b946dbcc
This diff is collapsed.
......@@ -291,6 +291,7 @@ var
function lua_tointeger(L: lua_State; idx: Integer): lua_Integer; inline;
function lua_tounsigned(L: lua_State; idx: Integer): lua_Unsigned; inline;
procedure lua_pop(L: lua_State; n: Integer); inline;
(*
#define lua_pop(L,n) lua_settop(L, -(n)-1)
......@@ -626,6 +627,11 @@ begin
Result := lua_tounsignedx(L, idx, nil);
end;
procedure lua_pop(L: lua_State; n: Integer);
begin
lua_settop(L, -(n) - 1);
end;
procedure lua_pushcfunction(L: lua_State; f: lua_CFunction);
begin
lua_pushcclosure(L, f, 0);
......
......@@ -22,10 +22,11 @@ type
property Printed: TStringBuilder read FPrinted;
published
procedure NewState;
procedure LoadAndCallFromString;
procedure LoadAndCallFromStream;
procedure LoadAndRunFromString;
procedure LoadAndRunFromStream;
procedure FunctionResult;
procedure CallLuaFunction;
end;
......@@ -70,18 +71,18 @@ end;
procedure TTestWrapper.LoadAndCallFromString;
procedure TTestWrapper.LoadAndRunFromString;
begin
Lua.LoadFromString('print("Hello world!")');
Lua.Call;
Lua.Run;
CheckEquals('Hello world!', Printed.ToString);
end;
procedure TTestWrapper.LoadAndCallFromStream;
procedure TTestWrapper.LoadAndRunFromStream;
begin
Lua.LoadFromStream(TStringStream.Create('print("Hello world!")'));
Lua.Call;
Lua.Run;
CheckEquals('Hello world!', Printed.ToString);
end;
......@@ -95,11 +96,26 @@ begin
end);
Lua.LoadFromString('print(myuppercase("Hello world!"))');
Lua.Call;
Lua.Run;
CheckEquals('HELLO WORLD!', Printed.ToString);
end;
procedure TTestWrapper.CallLuaFunction;
var
returnValues: ILuaReadParameters;
begin
Lua.LoadFromString('function sum(a, b)'#13#10 +
' return a + b'#13#10 +
'end');
returnValues := Lua.Call('sum', [1, 2]);
CheckEquals(1, returnValues.Count, 'returnValues Count');
CheckEquals(3, returnValues[0].AsInteger, 'returnValues[0]');
end;
initialization
RegisterTest(TTestWrapper.Suite);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment