luaconfig.pas

来自「从Delphi中调用lua」· PAS 代码 · 共 62 行

PAS
62
字号
unit luaConfig;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, lua, pLua, pLuaRecord;

implementation

uses
  MainForm;

function GetCaption(RecordPointer : pointer; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
  // Get the value of the caption and put it on the stack
  plua_pushstring(l, frmMain.Caption);
  result := 1;
end;

function SetCaption(RecordPointer : pointer; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
  // Get the new caption from the stack and set frmMain.Caption to it
  frmMain.Caption := plua_tostring(L, paramidxstart);
  result := 0;
end;

function GetColor(RecordPointer : pointer; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
  // Get the value of the Color and put it on the stack
  lua_pushinteger(l, frmMain.Color);
  result := 1;
end;

function SetColor(RecordPointer : pointer; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
  // Get the new Color from the stack and set frmMain.Color to it
  frmMain.Color := lua_tointeger(L, paramidxstart);
  result := 0;
end;

procedure Init;
var
  ri : PLuaRecordInfo;
begin
  // Create a virtual "Config" global variable (record) that will allow
  // the lua script to access application properties.
  ri := RecordTypesList.Add('TConfig');
  plua_AddRecordProperty(ri^, 'Caption', @GetCaption, @SetCaption);
  plua_AddRecordProperty(ri^, 'Color', @GetColor, @SetColor);
end;

initialization

Init;

finalization

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?