📄 luaparsernode.pas
字号:
unit luaParserNode;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, pLuaObject, lua, PasTree;
procedure RegisterExistingNode(L : PLua_State; Name : AnsiString; Node : TPasElement);
procedure PushExistingNode(L : PLua_State; Node : TPasElement);
implementation
uses
pLua;
function GetFileName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
itm := TPasElement(target);
plua_pushstring(l, itm.SourceFilename);
result := 1;
end;
function GetLineNumber(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
itm := TPasElement(target);
lua_pushinteger(l, itm.SourceLinenumber);
result := 1;
end;
function GetFullName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
itm := TPasElement(target);
plua_pushstring(l, itm.FullName);
result := 1;
end;
function GetPathName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
itm := TPasElement(target);
plua_pushstring(l, itm.PathName);
result := 1;
end;
function GetElementTypeName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
itm := TPasElement(target);
plua_pushstring(l, itm.ElementTypeName);
result := 1;
end;
function GetName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
itm := TPasElement(target);
plua_pushstring(l, itm.Name);
result := 1;
end;
function GetClassName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
itm := TPasElement(target);
plua_pushstring(l, itm.ClassName);
result := 1;
end;
function GetParent(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
nfo : PLuaInstanceInfo;
begin
itm := TPasElement(target);
if itm.Parent <> nil then
begin
nfo := plua_GetObjectInfo(l, itm.Parent);
if assigned(nfo) then
plua_PushObject(nfo)
else
lua_pushnil(l);
end
else
lua_pushnil(l);
result := 1;
end;
function GetDeclaration(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
itm : TPasElement;
begin
result := 0;
itm := TPasElement(target);
if lua_isboolean(L, paramidxstart) then
plua_pushstring(l, itm.GetDeclaration(lua_toboolean(l, paramidxstart)))
else
plua_pushstring(l, itm.GetDeclaration(true));
result := 1;
end;
function GetDestType(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasPointerType then
PushExistingNode(l, (target as TPasPointerType).DestType)
else if target is TPasAliasType then
PushExistingNode(l, (target as TPasAliasType).DestType)
else
result := 0;
end;
function GetPackageName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasModule then
plua_pushstring(l, (target as TPasModule).PackageName)
else
result := 0;
end;
function GetValue(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasResString then
plua_pushstring(l, (target as TPasResString).Value)
else if target is TPasEnumValue then
lua_pushinteger(l, (target as TPasEnumValue).Value)
else if target is TPasArgument then
plua_pushstring(l, (target as TPasArgument).Value)
else if target is TPasVariable then
plua_pushstring(l, (target as TPasVariable).Value)
else
result := 0;
end;
function GetRangeStart(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasRangeType then
plua_pushstring(l, (target as TPasRangeType).RangeStart)
else
result := 0;
end;
function GetRangeEnd(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasRangeType then
plua_pushstring(l, (target as TPasRangeType).RangeEnd)
else
result := 0;
end;
function GetIndexRange(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasArrayType then
plua_pushstring(l, (target as TPasArrayType).IndexRange)
else
result := 0;
end;
function GetIsPacked(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasArrayType then
lua_pushboolean(l, (target as TPasArrayType).IsPacked)
else if target is TPasRecordType then
lua_pushboolean(l, (target as TPasRecordType).IsPacked)
else if target is TPasClassType then
lua_pushboolean(l, (target as TPasClassType).IsPacked)
else
result := 0;
end;
function GetElType(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasArrayType then
PushExistingNode(l, (target as TPasArrayType).ElType)
else if target is TPasFileType then
PushExistingNode(l, (target as TPasFileType).ElType)
else
result := 0;
end;
function GetIsValueUsed(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasEnumValue then
lua_pushboolean(l, (target as TPasEnumValue).IsValueUsed)
else
result := 0;
end;
function GetAssignedValue(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasEnumValue then
plua_pushstring(l, (target as TPasEnumValue).AssignedValue)
else
result := 0;
end;
function GetGetEnumNames(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
var
idx : Integer;
nl : TStringList;
itm : TPasEnumType;
begin
result := 0;
if target is TPasEnumType then
begin
itm := TPasEnumType(target);
lua_newtable(L);
result := 1;
nl := TStringList.Create;
try
itm.GetEnumNames(nl);
for idx := 0 to nl.Count -1 do
begin
lua_pushinteger(l, idx+1);
plua_pushstring(l, nl[idx]);
lua_settable(L, -3);
end;
finally
nl.Free;
end;
end;
end;
function GetEnumType(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasSetType then
PushExistingNode(l, (target as TPasSetType).EnumType)
else
result := 0;
end;
function GetVariantName(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasRecordType then
plua_pushstring(l, (target as TPasRecordType).VariantName)
else
result := 0;
end;
function GetVariantType(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasRecordType then
PushExistingNode(l, (target as TPasRecordType).VariantType)
else
result := 0;
end;
function GetMembers(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasVariant then
PushExistingNode(l, (target as TPasVariant).Members)
else
result := 0;
end;
function GetObjKind(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasClassType then
begin
case (target as TPasClassType).ObjKind of
okObject : plua_pushstring(l, 'Object');
okClass : plua_pushstring(l, 'Class');
okInterface : plua_pushstring(l, 'Interface');
else
result := 0;
end;
end
else
result := 0;
end;
function GetAncestorType(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasClassType then
PushExistingNode(l, (target as TPasClassType).AncestorType)
else
result := 0;
end;
function GetInterfaceGUID(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasClassType then
plua_pushstring(l, (target as TPasClassType).InterfaceGUID)
else
result := 0;
end;
function GetAccess(target : TObject; l : Plua_State; paramidxstart, paramcount : integer) : Integer;
begin
result := 1;
if target is TPasArgument then
begin
case (target as TPasArgument).Access of
argDefault : plua_pushstring(l, 'Default');
argConst : plua_pushstring(l, 'Const');
argVar : plua_pushstring(l, 'Var');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -