2013-01-03 22:28:20 +00:00
|
|
|
unit LuaCollection;
|
|
|
|
|
|
|
|
|
|
{$mode delphi}
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
Classes, SysUtils,Lua, Lualib, lauxlib;
|
|
|
|
|
|
|
|
|
|
procedure collection_addMetaData(L: PLua_state; metatable: integer; userdata: integer );
|
2013-01-03 23:38:30 +00:00
|
|
|
procedure initializeLuaCollection;
|
2013-01-03 22:28:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses luaclass, luahandler, LuaObject;
|
|
|
|
|
|
|
|
|
|
function collection_clear(L: Plua_State): integer; cdecl;
|
|
|
|
|
var
|
|
|
|
|
collection: TCollection;
|
|
|
|
|
begin
|
|
|
|
|
collection:=luaclass_getClassObject(L);
|
|
|
|
|
collection.clear;
|
|
|
|
|
result:=0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function collection_getCount(L: PLua_State): integer; cdecl;
|
|
|
|
|
var
|
|
|
|
|
collection: TCollection;
|
|
|
|
|
begin
|
|
|
|
|
collection:=luaclass_getClassObject(L);
|
|
|
|
|
lua_pushinteger(L, collection.Count);
|
2015-09-05 12:31:29 +02:00
|
|
|
result:=1;
|
2013-01-03 22:28:20 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function collection_delete(L: Plua_State): integer; cdecl;
|
|
|
|
|
var
|
|
|
|
|
collection: TCollection;
|
|
|
|
|
begin
|
|
|
|
|
collection:=luaclass_getClassObject(L);
|
|
|
|
|
if lua_gettop(L)>=1 then
|
|
|
|
|
collection.Delete(lua_tointeger(L, -1));
|
|
|
|
|
|
|
|
|
|
result:=0;
|
|
|
|
|
end;
|
|
|
|
|
|
2022-12-07 12:28:52 +01:00
|
|
|
function collection_getItem(L: Plua_State): integer; cdecl;
|
|
|
|
|
var
|
|
|
|
|
collection: TCollection;
|
|
|
|
|
begin
|
|
|
|
|
result:=0;
|
|
|
|
|
collection:=luaclass_getClassObject(L);
|
|
|
|
|
if lua_gettop(L)>=1 then
|
|
|
|
|
begin
|
|
|
|
|
luaclass_newClass(L, collection.Items[lua_tointeger(L,1)]);
|
|
|
|
|
exit(1);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
2013-01-03 22:28:20 +00:00
|
|
|
procedure collection_addMetaData(L: PLua_state; metatable: integer; userdata: integer );
|
|
|
|
|
begin
|
2013-01-03 23:38:30 +00:00
|
|
|
object_addMetaData(L, metatable, userdata);
|
2013-01-03 22:28:20 +00:00
|
|
|
luaclass_addClassFunctionToTable(L, metatable, userdata, 'clear', collection_clear);
|
|
|
|
|
luaclass_addClassFunctionToTable(L, metatable, userdata, 'getCount', collection_getCount);
|
|
|
|
|
luaclass_addClassFunctionToTable(L, metatable, userdata, 'delete', collection_delete);
|
|
|
|
|
|
|
|
|
|
luaclass_addPropertyToTable(L, metatable, userdata, 'Count', collection_getCount, nil);
|
2022-12-07 12:28:52 +01:00
|
|
|
|
|
|
|
|
luaclass_addArrayPropertyToTable(L, metatable, userdata, 'Items', collection_getItem, nil);
|
|
|
|
|
luaclass_setDefaultArrayProperty(L, metatable, userdata, collection_getItem,nil);
|
2013-01-03 22:28:20 +00:00
|
|
|
end;
|
|
|
|
|
|
2013-01-03 23:38:30 +00:00
|
|
|
procedure initializeLuaCollection;
|
2013-01-03 22:28:20 +00:00
|
|
|
begin
|
|
|
|
|
lua_register(LuaVM, 'collection_clear', collection_clear);
|
|
|
|
|
lua_register(LuaVM, 'collection_getCount', collection_getCount);
|
|
|
|
|
lua_register(LuaVM, 'collection_delete', collection_delete);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
luaclass_register(Tcollection, collection_addMetaData);
|
|
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|