2013-01-01 14:32:10 +00:00
|
|
|
unit LuaCustomControl;
|
|
|
|
|
|
|
|
|
|
{$mode delphi}
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
Classes, SysUtils, Controls, lua, lualib, lauxlib;
|
|
|
|
|
|
|
|
|
|
procedure customcontrol_addMetaData(L: PLua_state; metatable: integer; userdata: integer );
|
|
|
|
|
procedure initializeLuaCustomControl;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
2017-04-10 20:15:32 +02:00
|
|
|
uses luahandler, luaclass, LuaWinControl, LuaCaller;
|
2013-01-01 14:32:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
function customControl_getCanvas(L: PLua_State): integer; cdecl;
|
|
|
|
|
var
|
|
|
|
|
parameters: integer;
|
|
|
|
|
c: TCustomControl;
|
|
|
|
|
i: integer;
|
|
|
|
|
begin
|
|
|
|
|
c:=luaclass_getClassObject(L);
|
|
|
|
|
if c.Canvas.handle=0 then
|
|
|
|
|
i:=c.Canvas.Pixels[0,0];
|
|
|
|
|
|
2014-05-05 08:44:05 +00:00
|
|
|
luaclass_newClass(L, c.Canvas);
|
2013-01-01 14:32:10 +00:00
|
|
|
result:=1;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-04-10 20:15:32 +02:00
|
|
|
function customControl_getOnPaint(L: PLua_State): integer; cdecl;
|
|
|
|
|
var
|
|
|
|
|
c: TCustomControl;
|
|
|
|
|
begin
|
|
|
|
|
c:=luaclass_getClassObject(L);
|
|
|
|
|
LuaCaller_pushMethodProperty(L, TMethod(c.OnPaint), 'TNotifyEvent');
|
|
|
|
|
result:=1;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function customControl_setOnPaint(L: PLua_State): integer; cdecl;
|
|
|
|
|
var
|
|
|
|
|
c: TCustomControl;
|
|
|
|
|
m: tmethod;
|
|
|
|
|
begin
|
|
|
|
|
if lua_gettop(L)>=1 then
|
|
|
|
|
begin
|
|
|
|
|
c:=luaclass_getClassObject(L);
|
|
|
|
|
m:=tmethod(c.OnPaint);
|
|
|
|
|
LuaCaller_setMethodProperty(L, m, 'TNotifyEvent', lua_gettop(L));
|
|
|
|
|
c.OnPaint:=tnotifyevent(m);
|
|
|
|
|
end;
|
|
|
|
|
result:=0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
2013-01-01 14:32:10 +00:00
|
|
|
procedure customcontrol_addMetaData(L: PLua_state; metatable: integer; userdata: integer );
|
|
|
|
|
begin
|
|
|
|
|
wincontrol_addMetaData(L, metatable, userdata);
|
|
|
|
|
luaclass_addClassFunctionToTable(L, metatable, userdata, 'getCanvas', customControl_getCanvas);
|
|
|
|
|
luaclass_addPropertyToTable(L, metatable, userdata, 'Canvas', customControl_getCanvas, nil);
|
2017-04-10 20:15:32 +02:00
|
|
|
luaclass_addPropertyToTable(L, metatable, userdata, 'OnPaint', customControl_getOnPaint, customControl_setOnPaint);
|
2013-01-01 14:32:10 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure initializeLuaCustomControl;
|
|
|
|
|
begin
|
|
|
|
|
lua_register(LuaVM, 'customControl_getCanvas', customControl_getCanvas);
|
|
|
|
|
lua_register(LuaVM, 'customcontrol_getCanvas', customControl_getCanvas);
|
|
|
|
|
end;
|
|
|
|
|
|
2021-02-15 21:13:52 +01:00
|
|
|
|
2013-01-01 14:32:10 +00:00
|
|
|
initialization
|
|
|
|
|
luaclass_register(TCustomControl, customcontrol_addMetaData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|