unit scripting;
interface
uses LUA;
procedure InitScripts;
procedure CloseScripts;
procedure LoadScript(Scriptname:
String);
procedure PublishFunctions;
// ### Here comes the Functions accessable from lua ###
function DisplayText(L: Lua_State):integer;
cdecl;
Var
Lua_Instance: Lua_State;
implementation
uses
Unit1;
procedure InitScripts;
begin
Lua_Instance := Lua_Open;
LuaOpen_Base(Lua_Instance);
end;
procedure CloseScripts;
begin
Lua_Close(Lua_Instance);
Lua_Instance :=
nil;
end;
procedure LoadScript(Scriptname:
String);
var
Sucess: Integer;
begin
Sucess := Lua_DoFile(Lua_Instance, PChar(Scriptname));
if Sucess = 2
then
Form1.DisplayText(1,0,0,2,'
The loading of the Script "' + Scriptname + '
" failed!');
end;
procedure PublishFunctions;
begin
lua_pushcfunction( Lua_Instance, DisplayText);
lua_setglobal( Lua_Instance, '
DisplayText' );
end;
function DisplayText(L: Lua_State):integer;
cdecl;
var
ArgCount: Integer;
Red,Blue,Green,Thickness : Single;
Text:
String;
begin
argCount := Lua_GetTop(L);
// Anzahl Parameter
if argCount = 5
then begin
Red := Lua_ToNumber(L,1);
Green := Lua_ToNumber(L,2);
Blue := Lua_ToNumber(L,3);
Thickness := Lua_ToNumber(L,4);
Text := Lua_ToString(L,5);
Form1.DisplayText(Red,Green,Blue,Thickness,Text);
end;
Lua_Pop(L, argCount);
Result := 0;
end;
end.