Pārlūkot izejas kodu

*** empty log message ***

Jean-Francois Goulet 19 gadi atpakaļ
vecāks
revīzija
3da27ca4c3

+ 118 - 0
LuaEdit/LuaCore/LuaConf.pas

@@ -0,0 +1,118 @@
+(*
+** $Id: LuaConf.pas,v 1.1 2006-11-21 00:36:22 jfgoulet Exp $
+** Configuration file for Lua
+** See Copyright Notice in lua.h
+**
+**   Translation form C and Delphi adaptation of Code : 
+**     Massimo Magnano, Jean-Francois Goulet 2006
+*)
+
+unit luaconf;
+
+interface
+
+type
+    ptrdiff_t = Integer;
+(*
+@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
+** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
+** machines, ptrdiff_t gives a good choice between int or long.)
+*)
+    LUA_INTEGER = ptrdiff_t;
+
+const
+(*
+@@ LUA_IDSIZE gives the maximum size for the description of the source
+@* of a function in debug information.
+** CHANGE it if you want a different size.
+*)
+    LUA_IDSIZE = 60;
+
+(*
+@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
+@* behavior.
+** CHANGE it to undefined as soon as you replace to 'luaL_registry'
+** your uses of 'luaL_openlib'
+*)
+    {$define LUA_COMPAT_OPENLIB}
+
+(*
+@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
+*)
+   BUFSIZ = 1024;
+   LUAL_BUFFERSIZE = BUFSIZ;
+
+(* }================================================================== *)
+
+(*
+@@ LUA_PROMPT is the default prompt used by stand-alone Lua.
+@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
+** CHANGE them if you want different prompts. (You can also change the
+** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
+*)
+const
+  LUA_PROMPT  = '> ';
+  LUA_PROMPT2 = '>> ';
+
+type
+(*
+** {==================================================================
+@@ LUA_NUMBER is the type of numbers in Lua.
+** CHANGE the following definitions only if you want to build Lua
+** with a number type different from double. You may also need to
+** change lua_number2int & lua_number2integer.
+** ===================================================================
+*)
+   {$define LUA_NUMBER_DOUBLE}
+    LUA_NUMBER = Double;
+
+const
+(*
+@@ LUA_NUMBER_SCAN is the format for reading numbers.
+@@ LUA_NUMBER_FMT is the format for writing numbers.
+@@ lua_number2str converts a number to a string.
+@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
+@@ lua_str2number converts a string to a number.
+*)
+  LUA_NUMBER_SCAN = '%lf';
+  LUA_NUMBER_FMT = '%.14g';
+
+(*
+@@ lua_readline defines how to show a prompt and then read a line from
+@* the standard input.
+@@ lua_saveline defines how to "save" a read line in a "history".
+@@ lua_freeline defines how to free a line read by lua_readline.
+** CHANGE them if you want to improve this functionality (e.g., by using
+** GNU readline and history facilities).
+
+function  lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
+procedure lua_saveline(L : Plua_State; idx : Integer);
+procedure lua_freeline(L : Plua_State; b : PChar);
+*)
+const
+  lua_stdin_is_tty = TRUE;
+
+
+implementation
+
+(*
+function  lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
+var
+  s : String;
+begin
+  Write(p);                        // show prompt
+  ReadLn(s);                       // get line
+  b := PChar(s);                   //   and return it
+  result := (b[0] <> #4);          // test for ctrl-D
+end;
+
+procedure lua_saveline(L : Plua_State; idx : Integer);
+begin
+end;
+
+procedure lua_freeline(L : Plua_State; b : PChar);
+begin
+end;
+*)
+
+end.

+ 21 - 0
LuaEdit/LuaCore/LuaEditDebugDLL.pas

@@ -0,0 +1,21 @@
+unit LuaEditDebugDLL;
+
+interface
+
+uses lua;
+
+function LuaEditDebugOpen :Plua_State;
+function LuaEditDebugStartFile(LuaState :Plua_State; Filename :PChar):Integer;
+function LuaEditDebugStart(LuaState :Plua_State; Code :PChar):Integer;
+procedure LuaEditDebugClose(LuaState :Plua_State);
+
+
+implementation
+
+function LuaEditDebugOpen; external 'LuaEditDebug.dll';
+function LuaEditDebugStartFile; external 'LuaEditDebug.dll';
+function LuaEditDebugStart; external 'LuaEditDebug.dll';
+procedure LuaEditDebugClose; external 'LuaEditDebug.dll';
+
+
+end.

+ 948 - 0
LuaEdit/LuaCore/LuaSyntax.pas

@@ -0,0 +1,948 @@
+{-------------------------------------------------------------------------------
+The contents of this file are subject to the Mozilla Public License
+Version 1.1 (the "License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+http://www.mozilla.org/MPL/
+
+Software distributed under the License is distributed on an "AS IS" basis,
+WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+the specific language governing rights and limitations under the License.
+
+Code template generated with SynGen.
+The original code is: Lua.pas, released 2004-10-27.
+Description: Lua Syntax Parser/Highlighter
+The initial author of this file is Jean-François Goulet.
+Copyright (c) 2004, all rights reserved.
+
+Contributors to the SynEdit and mwEdit projects are listed in the
+Contributors.txt file.
+
+Alternatively, the contents of this file may be used under the terms of the
+GNU General Public License Version 2 or later (the "GPL"), in which case
+the provisions of the GPL are applicable instead of those above.
+If you wish to allow use of your version of this file only under the terms
+of the GPL and not to allow others to use your version of this file
+under the MPL, indicate your decision by deleting the provisions above and
+replace them with the notice and other provisions required by the GPL.
+If you do not delete the provisions above, a recipient may use your version
+of this file under either the MPL or the GPL.
+
+$Id: LuaSyntax.pas,v 1.1 2006-11-21 00:42:58 jfgoulet Exp $
+
+You may retrieve the latest version of this file at the SynEdit home page,
+located at http://SynEdit.SourceForge.net
+
+-------------------------------------------------------------------------------}
+
+unit LuaSyntax;
+
+{$I SynEdit.inc}
+
+interface
+
+uses
+{$IFDEF SYN_CLX}
+  QGraphics,
+  QSynEditTypes,
+  QSynEditHighlighter,
+{$ELSE}
+  Graphics,
+  SynEditTypes,
+  SynEditHighlighter,
+{$ENDIF}
+  SysUtils,
+  Classes;
+
+type
+  TtkTokenKind = (
+    tkComment,
+    tkIdentifier,
+    tkKey,
+    tkLuaMString,
+    tkNull,
+    tkNumber,
+    tkOctal,
+    tkHex,
+    tkFloat,
+    tkSpace,
+    tkString,
+    tkUnknown);
+
+  TRangeState = (rsUnKnown, rsLuaComment, rsLuaMComment, rsLuaMString, rsString1, rsString2);
+
+  TProcTableProc = procedure of object;
+
+  PIdentFuncTableFunc = ^TIdentFuncTableFunc;
+  TIdentFuncTableFunc = function: TtkTokenKind of object;
+
+const
+  MaxKey = 110;
+
+type
+  TSynLuaSyn = class(TSynCustomHighlighter)
+  private
+    fLineRef: string;
+    fLine: PChar;
+    fLineNumber: Integer;
+    fProcTable: array[#0..#255] of TProcTableProc;
+    fRange: TRangeState;
+    Run: LongInt;
+    fStringLen: Integer;
+    fToIdent: PChar;
+    fTokenPos: Integer;
+    fTokenID: TtkTokenKind;
+    fIdentFuncTable: array[0 .. MaxKey] of TIdentFuncTableFunc;
+    fCommentAttri: TSynHighlighterAttributes;
+    fIdentifierAttri: TSynHighlighterAttributes;
+    fKeyAttri: TSynHighlighterAttributes;
+    fLuaMStringAttri: TSynHighlighterAttributes;
+    fNumberAttri: TSynHighlighterAttributes;
+    fSpaceAttri: TSynHighlighterAttributes;
+    fStringAttri: TSynHighlighterAttributes;
+    function KeyHash(ToHash: PChar): Integer;
+    function KeyComp(const aKey: string): Boolean;
+    function Func17: TtkTokenKind;
+    function Func21: TtkTokenKind;
+    function Func22: TtkTokenKind;
+    function Func25: TtkTokenKind;
+    function Func26: TtkTokenKind;
+    function Func35: TtkTokenKind;
+    function Func38: TtkTokenKind;
+    function Func42: TtkTokenKind;
+    function Func45: TtkTokenKind;
+    function Func48: TtkTokenKind;
+    function Func51: TtkTokenKind;
+    function Func52: TtkTokenKind;
+    function Func57: TtkTokenKind;
+    function Func61: TtkTokenKind;
+    function Func62: TtkTokenKind;
+    function Func67: TtkTokenKind;
+    function Func68: TtkTokenKind;
+    function Func70: TtkTokenKind;
+    function Func71: TtkTokenKind;
+    function Func81: TtkTokenKind;
+    function Func82: TtkTokenKind;
+    function Func102: TtkTokenKind;
+    function Func110: TtkTokenKind;
+    procedure IdentProc;
+    procedure UnknownProc;
+    function AltFunc: TtkTokenKind;
+    procedure InitIdent;
+    function IdentKind(MayBe: PChar): TtkTokenKind;
+    procedure MakeMethodTables;
+    procedure NullProc;
+    procedure SpaceProc;
+    procedure CRProc;
+    procedure LFProc;
+    procedure LuaCommentOpenProc;
+    procedure LuaCommentProc;
+    procedure LuaMCommentOpenProc;
+    procedure LuaMCommentProc;
+    procedure LuaMStringOpenProc;
+    procedure LuaMStringProc;
+    procedure String1OpenProc;
+    procedure String1Proc;
+    procedure String2OpenProc;
+    procedure String2Proc;
+    procedure NumberProc;
+  protected
+    function GetIdentChars: TSynIdentChars; override;
+    function GetSampleSource: string; override;
+    function IsFilterStored: Boolean; override;
+  public
+    constructor Create(AOwner: TComponent); override;
+    {$IFNDEF SYN_CPPB_1} class {$ENDIF}
+    function GetLanguageName: string; override;
+    function GetRange: Pointer; override;
+    procedure ResetRange; override;
+    procedure SetRange(Value: Pointer); override;
+    function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes; override;
+    function GetEol: Boolean; override;
+    function GetKeyWords: string;
+    function GetTokenID: TtkTokenKind;
+    procedure SetLine(NewValue: String; LineNumber: Integer); override;
+    function GetToken: String; override;
+    function GetTokenAttribute: TSynHighlighterAttributes; override;
+    function GetTokenKind: integer; override;
+    function GetTokenPos: Integer; override;
+    procedure Next; override;
+  published
+    property CommentAttri: TSynHighlighterAttributes read fCommentAttri write fCommentAttri;
+    property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri write fIdentifierAttri;
+    property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
+    property LuaMStringAttri: TSynHighlighterAttributes read fLuaMStringAttri write fLuaMStringAttri;
+    property NumberAttri: TSynHighlighterAttributes read fNumberAttri write fNumberAttri;
+    property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri write fSpaceAttri;
+    property StringAttri: TSynHighlighterAttributes read fStringAttri write fStringAttri;
+  end;
+
+implementation
+
+uses
+{$IFDEF SYN_CLX}
+  QSynEditStrConst;
+{$ELSE}
+  SynEditStrConst;
+{$ENDIF}
+
+{$IFDEF SYN_COMPILER_3_UP}
+resourcestring
+{$ELSE}
+const
+{$ENDIF}
+  SYNS_FilterLua = 'Lua Files (*.lua, *.lpr)|*.lua;*.lpr';
+  SYNS_LangLua = 'Lua';
+  SYNS_AttrLuaMString = 'LuaMString';
+  SYNS_AttrNumber = 'Numbers';
+
+var
+  Identifiers: array[#0..#255] of ByteBool;
+  mHashTable : array[#0..#255] of Integer;
+
+procedure MakeIdentTable;
+var
+  I: Char;
+begin
+  for I := #0 to #255 do
+  begin
+    case I of
+      '_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
+    else
+      Identifiers[I] := False;
+    end;
+    case I in ['_', 'A'..'Z', 'a'..'z'] of
+      True:
+        begin
+          if (I > #64) and (I < #91) then
+            mHashTable[I] := Ord(I) - 64
+          else if (I > #96) then
+            mHashTable[I] := Ord(I) - 95;
+        end;
+    else
+      mHashTable[I] := 0;
+    end;
+  end;
+end;
+
+procedure TSynLuaSyn.InitIdent;
+var
+  I: Integer;
+  pF: PIdentFuncTableFunc;
+begin
+  pF := PIdentFuncTableFunc(@fIdentFuncTable);
+  for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do
+  begin
+    pF^ := AltFunc;
+    Inc(pF);
+  end;
+  fIdentFuncTable[17] := Func17;
+  fIdentFuncTable[21] := Func21;
+  fIdentFuncTable[22] := Func22;
+  fIdentFuncTable[25] := Func25;
+  fIdentFuncTable[26] := Func26;
+  fIdentFuncTable[35] := Func35;
+  fIdentFuncTable[38] := Func38;
+  fIdentFuncTable[42] := Func42;
+  fIdentFuncTable[45] := Func45;
+  fIdentFuncTable[48] := Func48;
+  fIdentFuncTable[51] := Func51;
+  fIdentFuncTable[52] := Func52;
+  fIdentFuncTable[57] := Func57;
+  fIdentFuncTable[61] := Func61;
+  fIdentFuncTable[62] := Func62;
+  fIdentFuncTable[67] := Func67;
+  fIdentFuncTable[68] := Func68;
+  fIdentFuncTable[70] := Func70;
+  fIdentFuncTable[71] := Func71;
+  fIdentFuncTable[81] := Func81;
+  fIdentFuncTable[82] := Func82;
+  fIdentFuncTable[102] := Func102;
+  fIdentFuncTable[110] := Func110;
+end;
+
+function TSynLuaSyn.KeyHash(ToHash: PChar): Integer;
+begin
+  Result := 0;
+  while ToHash^ in ['_', 'a'..'z', 'A'..'Z'] do
+  begin
+    inc(Result, mHashTable[ToHash^]);
+    inc(ToHash);
+  end;
+  fStringLen := ToHash - fToIdent;
+end;
+
+function TSynLuaSyn.KeyComp(const aKey: String): Boolean;
+var
+  I: Integer;
+  Temp: PChar;
+begin
+  Temp := fToIdent;
+  if Length(aKey) = fStringLen then
+  begin
+    Result := True;
+    for i := 1 to fStringLen do
+    begin
+      if Temp^ <> aKey[i] then
+      begin
+        Result := False;
+        break;
+      end;
+      inc(Temp);
+    end;
+  end else Result := False;
+end;
+
+function TSynLuaSyn.Func17: TtkTokenKind;
+begin
+  if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func21: TtkTokenKind;
+begin
+  if KeyComp('do') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func22: TtkTokenKind;
+begin
+  if KeyComp('and') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func25: TtkTokenKind;
+begin
+  if KeyComp('in') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func26: TtkTokenKind;
+begin
+  if KeyComp('end') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func35: TtkTokenKind;
+begin
+  if KeyComp('or') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func38: TtkTokenKind;
+begin
+  if KeyComp('nil') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func42: TtkTokenKind;
+begin
+  if KeyComp('for') then Result := tkKey else
+    if KeyComp('break') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func45: TtkTokenKind;
+begin
+  if KeyComp('else') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func48: TtkTokenKind;
+begin
+  if KeyComp('local') then Result := tkKey else
+    if KeyComp('false') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func51: TtkTokenKind;
+begin
+  if KeyComp('then') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func52: TtkTokenKind;
+begin
+  if KeyComp('not') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func57: TtkTokenKind;
+begin
+  if KeyComp('loaddll') then Result := tkIdentifier else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func61: TtkTokenKind;
+begin
+  if KeyComp('asd') then Result := tkIdentifier else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func62: TtkTokenKind;
+begin
+  if KeyComp('while') then Result := tkKey else
+    if KeyComp('print') then Result := tkIdentifier else
+      if KeyComp('elseif') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func67: TtkTokenKind;
+begin
+  if KeyComp('asd') then Result := tkIdentifier else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func68: TtkTokenKind;
+begin
+  if KeyComp('true') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func70: TtkTokenKind;
+begin
+  if KeyComp('asd') then Result := tkIdentifier else
+    if KeyComp('asd') then Result := tkIdentifier else
+      if KeyComp('dofile') then Result := tkIdentifier else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func71: TtkTokenKind;
+begin
+  if KeyComp('repeat') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func81: TtkTokenKind;
+begin
+  if KeyComp('until') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func82: TtkTokenKind;
+begin
+  if KeyComp('asd') then Result := tkIdentifier else
+    if KeyComp('asd') then Result := tkIdentifier else
+      if KeyComp('beep') then Result := tkIdentifier else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func102: TtkTokenKind;
+begin
+  if KeyComp('return') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.Func110: TtkTokenKind;
+begin
+  if KeyComp('function') then Result := tkKey else Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.AltFunc: TtkTokenKind;
+begin
+  Result := tkIdentifier;
+end;
+
+function TSynLuaSyn.IdentKind(MayBe: PChar): TtkTokenKind;
+var
+  HashKey: Integer;
+begin
+  fToIdent := MayBe;
+  HashKey := KeyHash(MayBe);
+  if HashKey <= MaxKey then
+    Result := fIdentFuncTable[HashKey]
+  else
+    Result := tkIdentifier;
+end;
+
+procedure TSynLuaSyn.MakeMethodTables;
+var
+  I: Char;
+begin
+  for I := #0 to #255 do
+    case I of
+      #0: fProcTable[I] := NullProc;
+      #10: fProcTable[I] := LFProc;
+      #13: fProcTable[I] := CRProc;
+      '-': fProcTable[I] := LuaCommentOpenProc;
+      '[': fProcTable[I] := LuaMStringOpenProc;
+      '"': fProcTable[I] := String1OpenProc;
+      '''': fProcTable[I] := String2OpenProc;
+      #1..#9, #11, #12, #14..#32 : fProcTable[I] := SpaceProc;
+      '0'..'9': fProcTable[I] := NumberProc;
+      'A'..'Z', 'a'..'z', '_': fProcTable[I] := IdentProc;
+    else
+      fProcTable[I] := UnknownProc;
+    end;
+end;
+
+procedure TSynLuaSyn.SpaceProc;
+begin
+  fTokenID := tkSpace;
+  repeat
+    inc(Run);
+  until not (fLine[Run] in [#1..#32]);
+end;
+
+procedure TSynLuaSyn.NullProc;
+begin
+  fTokenID := tkNull;
+end;
+
+procedure TSynLuaSyn.CRProc;
+begin
+  fTokenID := tkSpace;
+  inc(Run);
+  if fLine[Run] = #10 then
+    inc(Run);
+end;
+
+procedure TSynLuaSyn.LFProc;
+begin
+  fTokenID := tkSpace;
+  inc(Run);
+end;
+
+procedure TSynLuaSyn.LuaCommentOpenProc;
+begin
+  Inc(Run);
+  if (fLine[Run] = '-') and
+     (fLine[Run + 1] = '[') and
+     (fLine[Run + 2] = '[') then
+  begin
+    LuaMCommentOpenProc;
+  end
+  else if (fLine[Run] = '-') then
+  begin
+    fRange := rsLuaComment;
+    LuaCommentProc;
+    fTokenID := tkComment;
+  end
+  else
+    fTokenID := tkIdentifier;
+end;
+
+procedure TSynLuaSyn.LuaCommentProc;
+begin
+  fTokenID := tkComment;
+  repeat
+    if (fLine[Run] = '@') and
+       (fLine[Run + 1] = '£') and
+       (fLine[Run + 2] = '¤') and
+       (fLine[Run + 3] = '£') and
+       (fLine[Run + 4] = '@') and
+       (fLine[Run + 5] = '¢') and
+       (fLine[Run + 6] = '£') and
+       (fLine[Run + 7] = '@') then
+    begin
+      Inc(Run, 8);
+      fRange := rsUnKnown;
+      Break;
+    end;
+    if not (fLine[Run] in [#0, #10, #13]) then
+      Inc(Run);
+  until fLine[Run] in [#0, #10, #13];
+end;
+
+procedure TSynLuaSyn.LuaMCommentOpenProc;
+begin
+  fRange := rsLuaMComment;
+  LuaMCommentProc;
+  fTokenID := tkComment;
+end;
+
+procedure TSynLuaSyn.LuaMCommentProc;
+begin
+  case fLine[Run] of
+     #0: NullProc;
+    #10: LFProc;
+    #13: CRProc;
+  else
+    begin
+      fTokenID := tkComment;
+      repeat
+        if (fLine[Run] = ']') and
+           (fLine[Run + 1] = ']') then
+        begin
+          Inc(Run, 2);
+          fRange := rsUnKnown;
+          Break;
+        end;
+        if not (fLine[Run] in [#0, #10, #13]) then
+          Inc(Run);
+      until fLine[Run] in [#0, #10, #13];
+    end;
+  end;
+end;
+
+procedure TSynLuaSyn.LuaMStringOpenProc;
+begin
+  Inc(Run);
+  if (fLine[Run] = '[') then
+  begin
+    fRange := rsLuaMString;
+    LuaMStringProc;
+    fTokenID := tkLuaMString;
+  end
+  else
+    fTokenID := tkIdentifier;
+end;
+
+procedure TSynLuaSyn.LuaMStringProc;
+begin
+  case fLine[Run] of
+     #0: NullProc;
+    #10: LFProc;
+    #13: CRProc;
+  else
+    begin
+      fTokenID := tkLuaMString;
+      repeat
+        if (fLine[Run] = ']') and
+           (fLine[Run + 1] = ']') then
+        begin
+          Inc(Run, 2);
+          fRange := rsUnKnown;
+          Break;
+        end;
+        if not (fLine[Run] in [#0, #10, #13]) then
+          Inc(Run);
+      until fLine[Run] in [#0, #10, #13];
+    end;
+  end;
+end;
+
+procedure TSynLuaSyn.NumberProc;
+var
+  idx1: Integer; // token[1]
+  i: Integer;
+begin
+  idx1 := Run;
+  Inc(Run);
+  fTokenID := tkNumber;
+  while FLine[Run] in
+    ['0'..'9', 'A'..'F', 'a'..'f', '.', 'u', 'U', 'l', 'L', 'x', 'X', '-', '+'] do
+  begin
+    case FLine[Run] of
+      '.':
+        if FLine[Succ(Run)] = '.' then
+          Break
+        else
+          if (fTokenID <> tkHex) then
+            fTokenID := tkFloat
+          else // invalid
+          begin
+            fTokenID := tkUnknown;
+            Exit;
+          end;
+      '-', '+':
+        begin
+          if fTokenID <> tkFloat then // number <> float. an arithmetic operator
+            Exit;
+          if not (FLine[Pred(Run)] in ['e', 'E']) then
+            Exit; // number = float, but no exponent. an arithmetic operator
+          if not (FLine[Succ(Run)] in ['0'..'9', '+', '-']) then // invalid
+          begin
+            Inc(Run);
+            fTokenID := tkUnknown;
+            Exit;
+          end
+        end;
+      '0'..'7':
+        if (Run = Succ(idx1)) and (FLine[idx1] = '0') then // octal number
+          fTokenID := tkNumber; // Jean-François Goulet - Changed for token Number because token Octal was plain text and cannot be modified...
+      '8', '9':
+        if (FLine[idx1] = '0') and
+           ((fTokenID <> tkHex) and (fTokenID <> tkFloat)) then // invalid octal char
+             fTokenID := tkUnknown;
+      'a'..'d', 'A'..'D':
+        if fTokenID <> tkHex then // invalid char
+          Break;
+      'e', 'E':
+        if (fTokenID <> tkHex) then
+          if FLine[Pred(Run)] in ['0'..'9'] then // exponent
+          begin
+            for i := idx1 to Pred(Run) do
+              if FLine[i] in ['e', 'E'] then // too many exponents
+              begin
+                fTokenID := tkUnknown;
+                Exit;
+              end;
+            if not (FLine[Succ(Run)] in ['0'..'9', '+', '-']) then
+              Break
+            else
+              fTokenID := tkFloat
+          end
+          else // invalid char
+            Break;
+      'f', 'F':
+        if fTokenID <> tkHex then
+        begin
+          for i := idx1 to Pred(Run) do
+            if FLine[i] in ['f', 'F'] then // declaration syntax error
+            begin
+              fTokenID := tkUnknown;
+              Exit;
+            end;
+          if fTokenID = tkFloat then
+          begin
+            if fLine[Pred(Run)] in ['l', 'L'] then // can't mix
+              Break;
+          end
+          else
+            fTokenID := tkFloat;
+        end;
+      'l', 'L':
+        begin
+          for i := idx1 to Pred(Run) do
+            if FLine[i] in ['l', 'L'] then // declaration syntax error
+            begin
+              fTokenID := tkUnknown;
+              Exit;
+            end;
+          if fTokenID = tkFloat then
+            if fLine[Pred(Run)] in ['f', 'F'] then // can't mix
+              Break;
+        end;
+      'u', 'U':
+        if fTokenID = tkFloat then // not allowed
+          Break
+        else
+          for i := idx1 to Pred(Run) do
+            if FLine[i] in ['u', 'U'] then // declaration syntax error
+            begin
+              fTokenID := tkUnknown;
+              Exit;
+            end;
+      'x', 'X':
+        if (Run = Succ(idx1)) and   // 0x... 'x' must be second char
+           (FLine[idx1] = '0') and  // 0x...
+           (FLine[Succ(Run)] in ['0'..'9', 'a'..'f', 'A'..'F']) then // 0x... must be continued with a number
+             fTokenID := tkHex
+           else // invalid char
+           begin
+             if (not Identifiers[fLine[Succ(Run)]]) and
+                (FLine[Succ(idx1)] in ['x', 'X']) then
+             begin
+               Inc(Run); // highlight 'x' too
+               fTokenID := tkUnknown;
+             end;
+             Break;
+           end;
+    end; // case
+    Inc(Run);
+  end; // while
+  if FLine[Run] in ['A'..'Z', 'a'..'z', '_'] then
+    fTokenID := tkUnknown;
+end;
+
+procedure TSynLuaSyn.String1OpenProc;
+begin
+  Inc(Run);
+  fRange := rsString1;
+  String1Proc;
+  fTokenID := tkString;
+end;
+
+procedure TSynLuaSyn.String1Proc;
+begin
+  fTokenID := tkString;
+  repeat
+    if (((fLine[Run] = '"') and (fLine[Run - 1] <> '\')) or ((fLine[Run - 1] = '\') and (fLine[Run - 2] = '\') and (fLine[Run] = '"'))) then
+    begin
+      Inc(Run, 1);
+      fRange := rsUnKnown;
+      Break;
+    end;
+    if not (fLine[Run] in [#0, #10, #13]) then
+      Inc(Run);
+  until fLine[Run] in [#0, #10, #13];
+end;
+
+procedure TSynLuaSyn.String2OpenProc;
+begin
+  Inc(Run);
+  fRange := rsString2;
+  String2Proc;
+  fTokenID := tkString;
+end;
+
+procedure TSynLuaSyn.String2Proc;
+begin
+  fTokenID := tkString;
+  repeat
+    if (fLine[Run] = '''') then
+    begin
+      Inc(Run, 1);
+      fRange := rsUnKnown;
+      Break;
+    end;
+    if not (fLine[Run] in [#0, #10, #13]) then
+      Inc(Run);
+  until fLine[Run] in [#0, #10, #13];
+end;
+
+constructor TSynLuaSyn.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+  fCommentAttri := TSynHighLighterAttributes.Create(SYNS_AttrComment);
+  fCommentAttri.Style := [fsItalic];
+  fCommentAttri.Foreground := clGray;
+  AddAttribute(fCommentAttri);
+
+  fIdentifierAttri := TSynHighLighterAttributes.Create(SYNS_AttrIdentifier);
+  AddAttribute(fIdentifierAttri);
+
+  fKeyAttri := TSynHighLighterAttributes.Create(SYNS_AttrReservedWord);
+  fKeyAttri.Style := [fsBold];
+  AddAttribute(fKeyAttri);
+
+  fLuaMStringAttri := TSynHighLighterAttributes.Create(SYNS_AttrLuaMString);
+  fLuaMStringAttri.Foreground := clNavy;
+  AddAttribute(fLuaMStringAttri);
+
+  fNumberAttri := TSynHighLighterAttributes.Create(SYNS_AttrNumber);
+  fNumberAttri.Foreground := clBlue;
+  AddAttribute(fNumberAttri);
+
+  fSpaceAttri := TSynHighLighterAttributes.Create(SYNS_AttrSpace);
+  AddAttribute(fSpaceAttri);
+
+  fStringAttri := TSynHighLighterAttributes.Create(SYNS_AttrString);
+  fStringAttri.Foreground := clNavy;
+  AddAttribute(fStringAttri);
+
+  SetAttributesOnChange(DefHighlightChange);
+  InitIdent;
+  MakeMethodTables;
+  fDefaultFilter := SYNS_FilterLua;
+  fRange := rsUnknown;
+end;
+
+procedure TSynLuaSyn.SetLine(NewValue: String; LineNumber: Integer);
+begin
+  fLineRef := NewValue;
+  fLine := PChar(fLineRef);
+  Run := 0;
+  fLineNumber := LineNumber;
+  Next;
+end;
+
+procedure TSynLuaSyn.IdentProc;
+begin
+  fTokenID := IdentKind((fLine + Run));
+  inc(Run, fStringLen);
+  while Identifiers[fLine[Run]] do
+    Inc(Run);
+end;
+
+procedure TSynLuaSyn.UnknownProc;
+begin
+{$IFDEF SYN_MBCSSUPPORT}
+  if FLine[Run] in LeadBytes then
+    Inc(Run,2)
+  else
+{$ENDIF}
+  inc(Run);
+  fTokenID := tkUnknown;
+end;
+
+procedure TSynLuaSyn.Next;
+begin
+  fTokenPos := Run;
+  case fRange of
+    rsLuaMComment: LuaMCommentProc;
+    rsLuaMString: LuaMStringProc;
+  else
+    begin
+      fRange := rsUnknown;
+      fProcTable[fLine[Run]];
+    end;
+  end;
+end;
+
+function TSynLuaSyn.GetDefaultAttribute(Index: integer): TSynHighLighterAttributes;
+begin
+  case Index of
+    SYN_ATTR_COMMENT    : Result := fCommentAttri;
+    SYN_ATTR_IDENTIFIER : Result := fIdentifierAttri;
+    SYN_ATTR_KEYWORD    : Result := fKeyAttri;
+    SYN_ATTR_STRING     : Result := fStringAttri;
+    SYN_ATTR_WHITESPACE : Result := fSpaceAttri;
+  else
+    Result := nil;
+  end;
+end;
+
+function TSynLuaSyn.GetEol: Boolean;
+begin
+  Result := fTokenID = tkNull;
+end;
+
+function TSynLuaSyn.GetKeyWords: string;
+begin
+  Result := 
+    'and,break,do,dofile,else,elseif,end,exit,false,for,function,if,in,loa' +
+    'ddll,local,nil,not,or,print,repeat,return,Sleep,then,true,type,until,w' +
+    'hile';
+end;
+
+function TSynLuaSyn.GetToken: String;
+var
+  Len: LongInt;
+begin
+  Len := Run - fTokenPos;
+  SetString(Result, (FLine + fTokenPos), Len);
+end;
+
+function TSynLuaSyn.GetTokenID: TtkTokenKind;
+begin
+  Result := fTokenId;
+end;
+
+function TSynLuaSyn.GetTokenAttribute: TSynHighLighterAttributes;
+begin
+  case GetTokenID of
+    tkComment: Result := fCommentAttri;
+    tkIdentifier: Result := fIdentifierAttri;
+    tkKey: Result := fKeyAttri;
+    tkLuaMString: Result := fLuaMStringAttri;
+    tkNumber, tkFloat: Result := fNumberAttri;
+    tkSpace: Result := fSpaceAttri;
+    tkString: Result := fStringAttri;
+    tkUnknown: Result := fIdentifierAttri;
+  else
+    Result := nil;
+  end;
+end;
+
+function TSynLuaSyn.GetTokenKind: integer;
+begin
+  Result := Ord(fTokenId);
+end;
+
+function TSynLuaSyn.GetTokenPos: Integer;
+begin
+  Result := fTokenPos;
+end;
+
+function TSynLuaSyn.GetIdentChars: TSynIdentChars;
+begin
+  Result := ['_', 'a'..'z', 'A'..'Z'];
+end;
+
+function TSynLuaSyn.GetSampleSource: string;
+begin
+  Result := 'Sample source for: '#13#10 +
+            'Lua Syntax Parser/Highlighter';
+end;
+
+function TSynLuaSyn.IsFilterStored: Boolean;
+begin
+  Result := fDefaultFilter <> SYNS_FilterLua;
+end;
+
+{$IFNDEF SYN_CPPB_1} class {$ENDIF}
+function TSynLuaSyn.GetLanguageName: string;
+begin
+  Result := SYNS_LangLua;
+end;
+
+procedure TSynLuaSyn.ResetRange;
+begin
+  fRange := rsUnknown;
+end;
+
+procedure TSynLuaSyn.SetRange(Value: Pointer);
+begin
+  fRange := TRangeState(Value);
+end;
+
+function TSynLuaSyn.GetRange: Pointer;
+begin
+  Result := Pointer(fRange);
+end;
+
+initialization
+  MakeIdentTable;
+{$IFNDEF SYN_CPPB_1}
+  RegisterPlaceableHighlighter(TSynLuaSyn);
+{$ENDIF}
+end.

+ 58 - 0
LuaEdit/LuaCore/Lua_Assert.pas

@@ -0,0 +1,58 @@
+//******************************************************************************
+//***                     LUA SCRIPT FUNCTIONS                               ***
+//***                                                                        ***
+//***        (c) Massimo Magnano 2005                                        ***
+//***                                                                        ***
+//***                                                                        ***
+//******************************************************************************
+//  File        : Lua_Assert.pas
+//
+//  Description : Access from Lua scripts to RunTime Debug.
+//
+//******************************************************************************
+
+unit Lua_Assert;
+
+interface
+
+uses Lua, Classes;
+
+procedure RegisterFunctions(L: Plua_State);
+
+
+implementation
+
+uses LuaUtils, RTDebug, SysUtils;
+
+function LuaRTAssert(L: Plua_State): Integer; cdecl;
+Var
+   Condition   :Boolean;
+   TrueStr,
+   FalseStr    :String;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=3)
+     then begin
+               try
+                  Condition := LuaToBoolean(L, 1);
+                  TrueStr   := LuaToString(L, 2);
+                  FalseStr  := LuaToString(L, 3);
+                  RTAssert(0, Condition, 'Lua : '+TrueStr, 'Lua : '+FalseStr, 0);
+               except
+                  On E:Exception do Result :=0;
+               end;
+          end;
+end;
+
+
+procedure RegisterFunctions(L: Plua_State);
+begin
+     LuaRegister(L, 'RTAssert', LuaRTAssert);
+end;
+
+
+end.

+ 84 - 0
LuaEdit/LuaCore/Lua_EnvironmentStrings.pas

@@ -0,0 +1,84 @@
+//******************************************************************************
+//***                     LUA SCRIPT FUNCTIONS                               ***
+//***                                                                        ***
+//***        (c) Massimo Magnano 2006                                        ***
+//***                                                                        ***
+//***                                                                        ***
+//******************************************************************************
+//  File        : Lua_EnvironmentStrings.pas
+//
+//  Description : Access from Lua scripts to EnvironmentStrings
+//
+//******************************************************************************
+//  Exported functions :
+//
+//   GetVarValue(string VarString)                       return Value as String.
+
+unit Lua_EnvironmentStrings;
+
+interface
+
+uses SysUtils, Lua, LuaUtils, EnvironmentStrings;
+
+procedure RegisterFunctions(L: Plua_State;
+                            OnGetVariable :TOnGetVariableFunction =Nil;
+                            OnGetVariableTag :TObject =Nil);
+
+implementation
+
+const
+     HANDLE_ONGETVARIABLE         ='Lua_ES_OnGetVariable';
+     HANDLE_ONGETVARIABLETAG      ='Lua_ES_OnGetVariableTag';
+
+
+function GetOnGetVariable(L: Plua_State): TOnGetVariableFunction;
+begin
+     Result := TOnGetVariableFunction(LuaGetTableLightUserData(L, LUA_REGISTRYINDEX, HANDLE_ONGETVARIABLE));
+end;
+
+function GetOnGetVariableTag(L: Plua_State): TObject;
+begin
+     Result := TObject(LuaGetTableLightUserData(L, LUA_REGISTRYINDEX, HANDLE_ONGETVARIABLETAG));
+end;
+
+//   GetVarValue(string VarString)                       return Value as String.
+function LuaGetVarValue(L: Plua_State): Integer; cdecl;
+Var
+   NParams      :Integer;
+   VarName      :String;
+   xResult      :String;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  VarName :=LuaToString(L, 1);
+                  xResult :=EnvironmentStrings.ProcessPARAMString(VarName, GetOnGetVariable(L), GetOnGetVariableTag(L));
+                  if (xResult<>'')
+                  then begin
+                            LuaPushString(L, xResult);
+                            Result := 1;
+                       end;
+               except
+                  On E:Exception do begin
+                                       LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+procedure RegisterFunctions(L: Plua_State;
+                            OnGetVariable :TOnGetVariableFunction =Nil;
+                            OnGetVariableTag :TObject =Nil);
+begin
+     LuaSetTableLightUserData(L, LUA_REGISTRYINDEX,
+                              HANDLE_ONGETVARIABLE, @OnGetVariable);
+     LuaSetTableLightUserData(L, LUA_REGISTRYINDEX,
+                              HANDLE_ONGETVARIABLETAG, OnGetVariableTag);
+     LuaRegister(L, 'GetVarValue', LuaGetVarValue);
+end;
+
+end.

+ 504 - 0
LuaEdit/LuaCore/Lua_Files.pas

@@ -0,0 +1,504 @@
+//******************************************************************************
+//***                     LUA SCRIPT FUNCTIONS                               ***
+//***                                                                        ***
+//***        (c) Massimo Magnano 2005                                        ***
+//***                                                                        ***
+//***                                                                        ***
+//******************************************************************************
+//  File        : Lua_Files.pas
+//
+//  Description : Access from Lua scripts to some file functions.
+//
+//******************************************************************************
+//  Exported functions :
+//
+//   CreateSearchRec {Path=string, Attr=integer}       return TSearchRec object.
+//      TSearchRec:FindFirst()                          return ErrorCode as Int.
+//      TSearchRec:FindNext()                           return ErrorCode as Int.
+//      TSearchRec:GetName()                          return FileName as string.
+//      TSearchRec:GetTime()                         return FileTime as integer.
+//      TSearchRec:GetSize()                         return FileSize as integer.
+//      TSearchRec:GetAttr()                         return FileAttr as integer.
+//      TSearchRec:IsDir()                              return IsDir as boolean.
+//      TSearchRec:FindClose()                                  free the object.
+//
+//   CopyPath(string SourcePath, DestPath, wild [, integer ExistingFlags, boolean Recursive])
+//   CopyFile(string SourceFile, DestPath [, integer ExistingFlags, string DestFileName])
+//   DeleteDir(string BaseDir, SelName, boolean Recursive, RemoveDirs)
+//   RegServer(string SourceFile)
+//   UnRegServer(string SourceFile)
+//                                                     return Status as boolean.
+
+
+unit Lua_Files;
+
+interface
+
+uses Lua, Classes, Lua_FunctionsLog;
+
+const
+    faOnlyFile  =$27;    //39 Decimal
+    faAnyDir    =$1F;    //31 Decimal
+
+
+procedure RegisterFunctions(L: Plua_State);
+
+
+implementation
+
+uses Windows, ShellApi, LuaUtils, SysUtils, CopyRoutines;
+
+const
+     HANDLE_SearchRecSTR ='Lua_Files_SearchRecHandle';
+
+type
+    TLuaSearchRec = record
+                       Path :String;
+                       Attr :Integer;
+                       Rec  :TSearchRec;
+                    end;
+    PLuaSearchRec =^TLuaSearchRec;
+
+//=============== Lua Functions Files Enumeration ==============================
+
+function GetPLuaSearchRec(L: Plua_State; Index: Integer): PLuaSearchRec;
+begin
+     Result := PLuaSearchRec(LuaGetTableLightUserData(L, Index, HANDLE_SearchRecSTR));
+     if (Result=Nil)
+     then raise Exception.Create('Unable to Get TSearchRec');
+end;
+
+function LuaFindFirstTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  LuaPushInteger(L, FindFirst(theRec^.Path, theRec^.Attr, theRec^.Rec));
+                  Result :=1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaFindNextTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  LuaPushInteger(L, FindNext(theRec^.Rec));
+                  Result :=1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaGetNameTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  LuaPushString(L, theRec^.Rec.Name);
+                  Result :=1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaGetTimeTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  LuaPushInteger(L, theRec^.Rec.Time);
+                  Result :=1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaGetSizeTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  LuaPushInteger(L, theRec^.Rec.Size);
+                  Result :=1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaGetAttrTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  LuaPushInteger(L, theRec^.Rec.Attr);
+                  Result :=1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaIsDirTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  LuaPushBoolean(L, ((theRec^.Rec.Attr and $10)<>0) and
+                                    ((theRec^.Rec.Name<>'.') and (theRec^.Rec.Name<>'..'))
+                                    );
+                  Result :=1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaFindCloseTSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   theRec      :PLuaSearchRec;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theRec :=GetPLuaSearchRec(L, 1);
+                  FindClose(theRec^.Rec);
+                  FreeMem(theRec);
+                  LuaSetTableClear(L, 1);
+                  LuaPushBoolean(L, True);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+
+function LuaCreateSearchRec(L: Plua_State): Integer; cdecl;
+Var
+   Path          :String;
+   Attr          :Integer;
+   xResult       :PLuaSearchRec;
+
+begin
+     Result := 0;
+
+     try
+        Path :=LuaGetTableString(L, 1, 'Path');
+        Attr :=LuaGetTableInteger(L, 1, 'Attr');
+        LuaSetTableNil(L, 1, 'Path');
+        LuaSetTableNil(L, 1, 'Attr');
+        GetMem(xResult, sizeOf(TLuaSearchRec));
+        if (xResult=Nil)
+        then raise Exception.Create('Unable to Create TSearchRec');
+        FillChar(xResult^, sizeOf(TLuaSearchRec), 0);
+        xResult^.Attr :=Attr;
+        xResult^.Path :=Path;
+        FillChar(xResult^.Rec, sizeOf(TSearchRec), 0);
+
+        LuaSetTableLightUserData(L, 1, HANDLE_SearchRecSTR, xResult);
+        LuaSetTableFunction(L, 1, 'FindFirst', LuaFindFirstTSearchRec);
+        LuaSetTableFunction(L, 1, 'FindNext', LuaFindNextTSearchRec);
+        LuaSetTableFunction(L, 1, 'GetName', LuaGetNameTSearchRec);
+        LuaSetTableFunction(L, 1, 'GetTime', LuaGetTimeTSearchRec);
+        LuaSetTableFunction(L, 1, 'GetSize', LuaGetSizeTSearchRec);
+        LuaSetTableFunction(L, 1, 'GetAttr', LuaGetAttrTSearchRec);
+        LuaSetTableFunction(L, 1, 'IsDir', LuaIsDirTSearchRec);
+
+        LuaSetTableFunction(L, 1, 'FindClose', LuaFindCloseTSearchRec);
+        LuaSetTableFunction(L, 1, 'Free', LuaFindCloseTSearchRec);
+        Result := 1;
+     except
+        On E:Exception do begin
+                               //LuaError(L, ERR_Script+E.Message);
+                          end;
+
+     end;
+end;
+
+//=============== Lua Functions Files Copy\Delete ==============================
+
+//   CopyPath(string SourcePath, DestPath, wild [, integer ExistingFlags, boolean Recursive])
+function LuaCopyPath(L: Plua_State): Integer; cdecl;
+Var
+   SourcePath,
+   DestPath,
+   wild           :String;
+   Recursive      :Boolean;
+   ExistingFlags,
+   NParams        :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams>=3)
+     then begin
+               try
+                  Recursive :=True;
+                  ExistingFlags :=EXISTING_IF_ASK;
+
+                  SourcePath :=LuaToString(L, 1);
+                  DestPath :=LuaToString(L, 2);
+                  wild :=LuaToString(L, 3);
+                  if (NParams>=4) and
+                     (lua_isnumber(L, 4)<>0)
+                  then ExistingFlags :=LuaToInteger(L, 4);
+
+                  if (NParams>=5) and
+                     (lua_isboolean(L, 5))
+                  then Recursive :=LuaToBoolean(L, 5);
+
+                  CopyPath(SourcePath, DestPath, wild, ExistingFlags, Recursive);
+
+                  DoFunctionLog('CopyPath', '"'+SourcePath+'"', '"'+DestPath+'"',
+                                '"'+wild+'"');
+
+                  LuaPushBoolean(L, True);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+//   CopyFile(string SourceFile, DestPath, integer ExistingFlags, string DestFileName)
+function LuaCopyFile(L: Plua_State): Integer; cdecl;
+Var
+   SourceFile,
+   DestPath,
+   DestFileName   :String;
+   ExistingFlags,
+   NParams        :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams>=2)
+     then begin
+               try
+                  DestFileName :='';
+                  ExistingFlags :=EXISTING_IF_ASK;
+
+                  SourceFile :=LuaToString(L, 1);
+                  DestPath :=LuaToString(L, 2);
+                  if (NParams>=3) and
+                     (lua_isnumber(L, 3)<>0)
+                  then ExistingFlags :=LuaToInteger(L, 3);
+                  if (NParams>=4) and
+                     (lua_isstring(L, 4)<>0)
+                  then DestFileName :=LuaToString(L, 4);
+
+                  CopyFile(SourceFile, DestPath, ExistingFlags, DestFileName);
+
+                  DoFunctionLog('CopyFile', '"'+SourceFile+'"', '"'+DestPath+'"',
+                                IntToStr(ExistingFlags), '"'+DestFileName+'"');
+
+                  LuaPushBoolean(L, True);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                  end;
+               end;
+          end;
+end;
+
+//   DeleteDir(string BaseDir, SelName, boolean Recursive, RemoveDirs)
+function LuaDeleteDir(L: Plua_State): Integer; cdecl;
+Var
+   BaseDir,
+   SelName     :String;
+   Recursive,
+   RemoveDirs  :Boolean;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=4)
+     then begin
+               try
+                  BaseDir    :=LuaToString(L, 1);
+                  SelName    :=LuaToString(L, 2);
+                  Recursive  :=LuaToBoolean(L, 3);
+                  RemoveDirs :=LuaToBoolean(L, 4);
+
+                  DeleteDir(BaseDir, SelName, Recursive, RemoveDirs);
+
+                  DoFunctionLog('DeleteDir', '"'+BaseDir+'"', '"'+SelName+'"',
+                                BoolToStr(Recursive, True), BoolToStr(RemoveDirs, True));
+
+                  LuaPushBoolean(L, True);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                  end;
+               end;
+          end;
+end;
+
+//   RegServer(string SourceFile)
+function LuaRegServer(L: Plua_State): Integer; cdecl;
+Var
+   SourceFile  :String;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  SourceFile :=LuaToString(L, 1);
+
+                  ShellExecute(GetDesktopWindow, 'open', PChar('REGSVR32'),
+                               PChar('/s '+'"'+SourceFile+'"'),
+                               Nil, SW_SHOWNORMAL);
+
+                  DoFunctionLog('RegServer', '"'+SourceFile+'"');
+
+                  LuaPushBoolean(L, True);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                  end;
+               end;
+          end;
+end;
+
+//   UnRegServer(string SourceFile)
+function LuaUnRegServer(L: Plua_State): Integer; cdecl;
+Var
+   SourceFile  :String;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  SourceFile :=LuaToString(L, 1);
+
+                  ShellExecute(GetDesktopWindow, 'open', PChar('REGSVR32'),
+                               PChar('/u /s '+'"'+SourceFile+'"'),
+                               Nil, SW_SHOWNORMAL);
+
+                  DoFunctionLog('UnRegServer', '"'+SourceFile+'"');
+
+                  LuaPushBoolean(L, True);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                  end;
+               end;
+          end;
+end;
+
+
+procedure RegisterFunctions(L: Plua_State);
+begin
+     LuaRegister(L, 'CreateSearchRec', LuaCreateSearchRec);
+     LuaRegister(L, 'CopyPath', LuaCopyPath);
+     LuaRegister(L, 'CopyFile', LuaCopyFile);
+     LuaRegister(L, 'DeleteDir', LuaDeleteDir);
+     LuaRegister(L, 'RegServer', LuaRegServer);
+     LuaRegister(L, 'UnRegServer', LuaUnRegServer);
+end;
+
+
+end.

+ 53 - 0
LuaEdit/LuaCore/Lua_FunctionsLog.pas

@@ -0,0 +1,53 @@
+//******************************************************************************
+//***                     LUA SCRIPT FUNCTIONS                               ***
+//***                                                                        ***
+//***        (c) Massimo Magnano 2005                                        ***
+//***                                                                        ***
+//***                                                                        ***
+//******************************************************************************
+//  File        : Lua_FunctionsLog.pas
+//
+//  Description : Do Log of Functions called inside a script.
+//
+//******************************************************************************
+unit Lua_FunctionsLog;
+
+interface
+
+type
+    Tfunction_LuaLog = procedure (FuncLog :PChar); stdcall;
+
+Var
+   OnLuaLog :Tfunction_LuaLog =Nil;
+
+procedure DoFunctionLog(FuncName :String;
+                        Param1 :String=''; Param2 :String='';
+                        Param3 :String=''; Param4 :String='');
+
+implementation
+
+procedure DoFunctionLog(FuncName :String;
+                        Param1 :String=''; Param2 :String='';
+                        Param3 :String=''; Param4 :String='');
+Var
+   xLog :String;
+
+begin
+     if Assigned(OnLuaLog)
+     then begin
+               xLog := FuncName+'(';
+               if (Param1<>'')
+               then xLog :=xLog+Param1;
+               if (Param2<>'')
+               then xLog :=xLog+', '+Param2;
+               if (Param3<>'')
+               then xLog :=xLog+', '+Param3;
+               if (Param4<>'')
+               then xLog :=xLog+', '+Param4;
+               xLog :=xLog+')';
+
+               OnLuaLog(PChar(xLog));
+          end;
+end;
+
+end.

+ 386 - 0
LuaEdit/LuaCore/Lua_MGList.pas

@@ -0,0 +1,386 @@
+//******************************************************************************
+//***                     LUA SCRIPT FUNCTIONS                               ***
+//***                                                                        ***
+//***        (c) Massimo Magnano 2005                                        ***
+//***                                                                        ***
+//***                                                                        ***
+//******************************************************************************
+//  File        : Lua_MGList.pas
+//
+//  Description : Access from Lua scripts to TMGList Classes
+//
+//******************************************************************************
+//
+//  Lua Exported functions :
+//
+//   GetMGList{Name=string}                               return TMGList object.
+//      TMGList:FindFirst()                              return Data as Pointer.
+//      TMGList:FindNext()                               return Data as Pointer.
+//      TMGList:FindClose()                            return Status as boolean.
+//      TMGList:GetCount()                                  return Count as Int.
+//      TMGList:GetData(integer DataPointer, string DataName)       return Data.
+//      TMGList:Find([variant Param1[,...[, ParamN]])    return Data as Pointer.
+
+
+unit Lua_MGList;
+
+interface
+
+uses Lua, Classes, MGList, Variants;
+
+function  AddMGList(Name :String; List :TMGList) :Boolean;
+function  DeleteMGList(Name :String) :Boolean;
+function  FindMGList(Name :String) :TMGList;
+procedure RegisterFunctions(L: Plua_State);
+
+implementation
+
+uses LuaUtils, SysUtils;
+
+const
+     HANDLE_STR ='Lua_MGList_Handle';
+
+type
+    TMGListDescr = record
+       Name     :String;
+       List     :TMGList;
+    end;
+    PMGListDescr = ^TMGListDescr;
+
+    TLuaMGList = class(TMGList)
+    protected
+        function allocData :Pointer; override;
+        procedure deallocData(pData :Pointer); override;
+        function FindByName(Tag :Integer; ptData1, ptData2 :Pointer) :Boolean;
+    public
+        function Find(Name :String): PMGListDescr;  overload;
+        function Add(Name :String; List :TMGList) :PMGListDescr; overload;
+        function Delete(Name :String) :Boolean; overload;
+    end;
+
+Var
+   LuaMGList :TLuaMGList =Nil;
+
+
+//========================== Lua Functions TMGList ==============================
+
+function GetPMGListDescr(L: Plua_State; Index: Integer): PMGListDescr;
+begin
+     Result := PMGListDescr(LuaGetTableLightUserData(L, Index, HANDLE_STR));
+end;
+
+function LuaFindFirstMGList(L: Plua_State): Integer; cdecl;
+Var
+   theList     :TMGList;
+   NParams     :Integer;
+   xFind       :Pointer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theList :=GetPMGListDescr(L, 1)^.List;
+                  xFind := theList.FindFirst;
+                  if (xFind<>Nil)
+                  then begin
+                            lua_pushlightuserdata(L, xFind);
+                            Result :=1;
+                       end;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaFindNextMGList(L: Plua_State): Integer; cdecl;
+Var
+   theList     :TMGList;
+   NParams     :Integer;
+   xFind       :Pointer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theList :=GetPMGListDescr(L, 1)^.List;
+                  xFind := theList.FindNext;
+                  if (xFind<>Nil)
+                  then begin
+                            lua_pushlightuserdata(L, xFind);
+                            Result :=1;
+                       end;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaFindCloseMGList(L: Plua_State): Integer; cdecl;
+Var
+   theList     :TMGList;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theList :=GetPMGListDescr(L, 1)^.List;
+                  theList.FindClose;
+                  LuaPushBoolean(L, True);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaGetCountMGList(L: Plua_State): Integer; cdecl;
+Var
+   theList     :TMGList;
+   NParams     :Integer;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=1)
+     then begin
+               try
+                  theList :=GetPMGListDescr(L, 1)^.List;
+                  LuaPushInteger(L, theList.Count);
+                  Result := 1;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+
+function LuaGetDataMGList(L: Plua_State): Integer; cdecl;
+Var
+   theListDescr :PMGListDescr;
+   NParams      :Integer;
+   DataName     :String;
+   CurrentData  :Pointer;
+   xResult      :Variant;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams=3)
+     then begin
+               try
+                  theListDescr :=GetPMGListDescr(L, 1);
+                  CurrentData  :=lua_touserdata(L, 2);
+                  DataName :=LuaToString(L, 3);
+                  if (CurrentData<>Nil)
+                  then begin
+                            xResult :=theListDescr^.List.GetData(CurrentData, DataName);
+                            LuaPushVariant(L, xResult);
+                            Result := 1;
+                       end;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+function LuaFindMGList(L: Plua_State): Integer; cdecl;
+Var
+   theListDescr :PMGListDescr;
+   NParams,
+   iParams      :Integer;
+   xResult      :Variant;
+   xFind        :Pointer;
+   theParams    :array of Variant;
+
+begin
+     Result := 0;
+
+     NParams := lua_gettop(L);
+     if (NParams>1)
+     then begin
+               try
+                  theListDescr :=GetPMGListDescr(L, 1);
+
+                  SetLength(theParams, (NParams-1));
+                  for iParams :=2 to NParams do
+                  begin
+                       xResult :=LuaToVariant(L, iParams);
+                       theParams[iParams-2] :=xResult;
+                  end;
+
+                  xFind  :=theListDescr^.List.Find(theParams);
+                  if (xFind<>Nil)
+                  then begin
+                            lua_pushlightuserdata(L, xFind);
+                            Result :=1;
+                       end;
+               except
+                  On E:Exception do begin
+                                       //LuaError(L, ERR_Script+E.Message);
+                                    end;
+               end;
+          end;
+end;
+
+
+function LuaGetMGList(L: Plua_State): Integer; cdecl;
+Var
+   ListName   :String;
+   xResult    :PMGListDescr;
+
+begin
+     Result := 0;
+
+     try
+        ListName :=LuaGetTableString(L, 1, 'Name');
+        LuaSetTableNil(L, 1, 'Name');
+        xResult :=LuaMGList.Find(ListName);
+        if (xResult=Nil)
+        then raise Exception.Create('Unable to Locate List '+ListName);
+
+        LuaSetTableLightUserData(L, 1, HANDLE_STR, xResult);
+        LuaSetTableFunction(L, 1, 'FindFirst', LuaFindFirstMGList);
+        LuaSetTableFunction(L, 1, 'FindNext', LuaFindNextMGList);
+        LuaSetTableFunction(L, 1, 'FindClose', LuaFindCloseMGList);
+        LuaSetTableFunction(L, 1, 'GetCount', LuaGetCountMGList);
+        LuaSetTableFunction(L, 1, 'GetData', LuaGetDataMGList);
+        LuaSetTableFunction(L, 1, 'Find', LuaFindMGList);
+        Result := 1;
+     except
+        On E:Exception do begin
+                               //LuaError(L, ERR_Script+E.Message);
+                          end;
+     end;
+end;
+
+//==============================================================================
+//======================== TLuaMGList Class ====================================
+
+function TLuaMGList.allocData :Pointer;
+begin
+     GetMem(Result, sizeOf(TMGListDescr));
+     FillChar(Result^, sizeOf(TMGListDescr), 0);
+end;
+
+procedure TLuaMGList.deallocData(pData :Pointer);
+begin
+     //Evito eventuali problemi per allocazione delle stringhe in Delphi.
+     PMGListDescr(pData)^.Name  :='';
+
+     FreeMem(pData, sizeOf(TMGListDescr));
+end;
+
+function TLuaMGList.FindByName(Tag :Integer; ptData1, ptData2 :Pointer) :Boolean;
+begin
+     Result := (String(PChar(ptData1)) = PMGListDescr(ptData2)^.Name);
+end;
+
+function TLuaMGList.Find(Name :String): PMGListDescr;
+
+begin
+     Result :=Self.ExtFind(PChar(Uppercase(Name)), 0, FindByName);
+end;
+
+function TLuaMGList.Add(Name :String; List :TMGList) :PMGListDescr;
+Var
+   toFind :PMGListDescr;
+
+begin
+     toFind :=Find(Name);
+
+     if (toFind=Nil)
+     then begin
+               toFind :=Self.Add;
+               toFind^.Name :=Uppercase(Name);
+          end;
+     toFind^.List :=List;
+     Result :=toFind;
+end;
+
+function TLuaMGList.Delete(Name :String) :Boolean;
+begin
+     Result :=Delete(PChar(Uppercase(Name)), 0, FindByName);
+end;
+
+//==============================================================================
+//======================== Public Functions ====================================
+
+function  AddMGList(Name :String; List :TMGList) :Boolean;
+begin
+     Result :=False;
+     if (LuaMGList<>Nil)
+     then begin
+               try
+                  Result := (LuaMGList.Add(Name, List) <> Nil);
+               except
+                  On E:Exception do begin end;
+               end;
+          end;
+end;
+
+function  DeleteMGList(Name :String) :Boolean;
+begin
+     Result :=False;
+     if (LuaMGList<>Nil)
+     then begin
+               try
+                  Result := LuaMGList.Delete(Name);
+               except
+                  On E:Exception do begin end;
+               end;
+          end;
+end;
+
+function  FindMGList(Name :String) :TMGList;
+Var
+   toFind :PMGListDescr;
+
+begin
+     Result :=Nil;
+     if (LuaMGList<>Nil)
+     then begin
+               try
+                  toFind :=LuaMGList.Find(Name);
+                  if (toFind<>Nil)
+                  then Result :=toFind.List;
+               except
+                  On E:Exception do begin end;
+               end;
+          end;
+end;
+
+procedure RegisterFunctions(L: Plua_State);
+begin
+     LuaRegister(L, 'GetMGList', LuaGetMGList);
+end;
+
+initialization
+   LuaMGList :=TLuaMGList.Create;
+
+finalization
+   LuaMGList.Free;
+   LuaMGList :=Nil;
+
+end.

+ 46 - 0
LuaEdit/LuaCore/readme.txt

@@ -0,0 +1,46 @@
+===============================================================================
+                                Lua for Delphi
+                                
+===============================================================================
+Authors :
+   Massimo Magnano      :  [email protected]
+   Jean-François Goulet :  [email protected]
+   Kuma                 :  [email protected]
+
+Supported Delphi Versions :
+  >= 6.0 
+
+-------------------------------------------------------------------------------
+
+MaxM :  I Use some common functions\classes implemented in the units under
+        the folder "Common", include this folder in your search directory
+        or simple move this files to a directory visible to delphi ide.
+        
+        RTDebug is a program to view assertions (useful in a place where you
+         cannot do a debug), you can download here 
+         
+         http://www.sortinonline.it/download/software/RTDebug/RunTimeDebug.zip
+        
+        For any questions contact-me.
+
+-------------------------------------------------------------------------------
+
+History
+v1.2 MaxM Adds : Units to access some functions from lua scripts 
+                  Lua_DB, Lua_Files, Lua_FunctionsLog, Lua_VCL (experimental)
+v1.1
+     MaxM Adds :
+             LuaPCallFunction
+
+v1.0
+     MaxM Adds :
+             LuaPushVariant
+             LuaToVariant
+             LuaGetTableInteger, LuaGet\SetTableTMethod
+             LuaLoadBufferFromFile
+     Solved Bugs : Stack problem in LuaProcessTableName
+                   LuaToInteger why Round?, Trunc is better
+
+v0.07	2004/10/03 First Release by [email protected]
+
+===============================================================================

+ 1 - 1
LuaEdit/Main.pas

@@ -741,7 +741,7 @@ function ParamCountEx(CommandLine: PChar): Integer; cdecl; external 'LuaEditSys.
 implementation
 
 uses
-  LuaSyntax, Search, Replace, ReplaceQuerry, GotoLine, About,
+  LuaVirtualTrees, LuaSyntax, Search, Replace, ReplaceQuerry, GotoLine, About,
   ProjectTree, Stack, Watch, Grids, AddToPrj, EditorSettings,
   PrjSettings, RemFromPrj, ErrorLookup, LuaStack, PrintSetup,
   Math, Contributors, LuaOutput, Breakpoints, LuaGlobals,