Browse Source

*** empty log message ***

Jean-Francois Goulet 19 years ago
parent
commit
3ab6319995
5 changed files with 702 additions and 1197 deletions
  1. 116 159
      LuaEdit/LuaCore/LuaUtils.pas
  2. 106 0
      LuaEdit/LuaCore/LuaVirtualTrees.pas
  3. 194 159
      LuaEdit/LuaCore/lauxlib.pas
  4. 269 824
      LuaEdit/LuaCore/lua.pas
  5. 17 55
      LuaEdit/LuaCore/lualib.pas

+ 116 - 159
LuaEdit/LuaCore/LuaUtils.pas

@@ -1,7 +1,7 @@
 //******************************************************************************
 //***                     LUA SCRIPT DELPHI UTILITIES                        ***
 //***                                                                        ***
-//***        (c) 2005 Jean-François Goulet,  Massimo Magnano, Kuma           ***
+//***        (c) 2006 Jean-François Goulet,  Massimo Magnano, Kuma           ***
 //***                                                                        ***
 //***                                                                        ***
 //******************************************************************************
@@ -12,9 +12,9 @@
 //******************************************************************************
 //** See Copyright Notice in lua.h
 
-//Revision 1.6
-//     JF Adds :
-//             LuaTableToVirtualTreeView
+//Revision 1.2
+//     MaxM Adds :
+//             GetCurrentFuncName, LuaSetTablePropertyFuncs
 //
 //Revision 1.1
 //     MaxM Adds :
@@ -33,7 +33,7 @@ unit LuaUtils;
 interface
 
 uses
-  SysUtils, Classes, ComCtrls, lua, lualib, lauxlib, Variants, VirtualTrees;
+  SysUtils, Classes, ComCtrls, luaconf, lua, lualib, lauxlib, Variants;
 
 const
      ERR_Script ='Script Error : ';  
@@ -48,12 +48,6 @@ type
     constructor Create(Title: string; Line: Integer; Msg: string);
   end;
 
-  PBasicTreeData = ^TBasicTreeData;
-  TBasicTreeData = record
-    sName: String;
-    sValue: String;
-  end;
-
   TVariantArray =array of Variant;
   PVariantArray =^TVariantArray;
 
@@ -97,6 +91,9 @@ procedure LuaSetTableFunction(L: Plua_State; TableIndex: Integer; const Key: str
 procedure LuaSetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string; P: Pointer);
 procedure LuaSetTableTMethod(L: Plua_State; TableIndex: Integer; const Key: string; M: TMethod);
 procedure LuaSetTableClear(L: Plua_State; TableIndex: Integer);
+procedure LuaSetTablePropertyFuncs(L: PLua_State; TableIndex: Integer;
+                                   ReadFunc: lua_CFunction;
+                                   WriteFunc: lua_CFunction =nil);
 procedure LuaRawSetTableValue(L: PLua_State; TableIndex: Integer; const Key: string; ValueIndex: Integer);
 procedure LuaRawSetTableNil(L: Plua_State; TableIndex: Integer; const Key: string);
 procedure LuaRawSetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string; B: Boolean);
@@ -109,16 +106,16 @@ function LuaGetMetaFunction(L: Plua_State; Index: Integer; Key: string): lua_CFu
 procedure LuaSetMetaFunction(L: Plua_State; Index: Integer; Key: string; F: lua_CFunction);
 
 procedure LuaShowStack(L: Plua_State; Caption: string = '');
-function LuaStackToStr(L: Plua_State; Index: Integer; MaxTable: Integer = -1; SubTableMax: Integer = 99; CheckCyclicReferencing: Boolean = True; TablePtrs: TList = nil): String;
+function LuaStackToStr(L: Plua_State; Index: Integer; MaxTable: Integer = -1; SubTableMax: Integer = 99): string;
 procedure LuaRegisterCustom(L: PLua_State; TableIndex: Integer; const Name: PChar; F: lua_CFunction);
 procedure LuaRegister(L: Plua_State; const Name: PChar; F: lua_CFunction);
 procedure LuaRegisterMetatable(L: Plua_State; const Name: PChar; F: lua_CFunction);
 procedure LuaRegisterProperty(L: PLua_State; const Name: PChar; ReadFunc, WriteFunc: lua_CFunction);
-procedure LuaStackToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer = -1; SubTableMax: Integer = 99; CheckCyclicReferencing: Boolean = True);
-procedure LuaLocalToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer = -1; Level: Integer = 0; SubTableMax: Integer = 99; CheckCyclicReferencing: Boolean = True);
-procedure LuaGlobalToStrings(L: PLua_State; Lines: TStrings; MaxTable: Integer = -1; SubTableMax: Integer = 99; CheckCyclicReferencing: Boolean = True);
-procedure LuaTableToStrings(L: Plua_State; Index: Integer; Lines: TStrings; MaxTable: Integer = -1; SubTableMax: Integer = 99; CheckCyclicReferencing: Boolean = True);
-procedure LuaTableToVirtualTreeView(L: Plua_State; Index: Integer; VTV: TVirtualStringTree; MaxTable: Integer; SubTableMax: Integer; CheckCyclicReferencing: Boolean);
+procedure LuaStackToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer = -1; SubTableMax: Integer = 99);
+procedure LuaLocalToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer = -1; Level: Integer = 0; SubTableMax: Integer = 99);
+procedure LuaGlobalToStrings(L: PLua_State; Lines: TStrings; MaxTable: Integer = -1; SubTableMax: Integer = 99);
+procedure LuaTableToStrings(L: Plua_State; Index: Integer; Lines: TStrings; MaxTable: Integer = -1; SubTableMax: Integer = 99);
+procedure LuaTableToTreeView(L: Plua_State; Index: Integer; TV: TTreeView; MaxTable: Integer = -1; SubTableMax: Integer = 99);
 function LuaGetIdentValue(L: Plua_State; Ident: string; MaxTable: Integer = -1): string;
 procedure LuaSetIdentValue(L: Plua_State; Ident, Value: string; MaxTable: Integer = -1);
 procedure LuaLoadBuffer(L: Plua_State; const Code: string; const Name: string);
@@ -134,6 +131,10 @@ procedure LuaErrorFmt(L: Plua_State; const Fmt: string; const Args: array of Con
 function LuaDataStrToStrings(const TableStr: string; Strings: TStrings): string;
 function LuaDoFile(L: Plua_State): Integer; cdecl;
 
+function LuaGetCurrentFuncName(L: Plua_State) :String;
+function Lua_VoidFunc(L: Plua_State): Integer; cdecl;
+
+
 const
   LuaGlobalVariableStr = '[LUA_GLOBALSINDEX]';
 var
@@ -141,7 +142,6 @@ var
   OnLuaStdout: TOnLuaStdout;
   DefaultMaxTable: Integer;
   SubTableCount: Integer;
-  SubTableCount2: Integer;
 
 implementation
 
@@ -154,20 +154,18 @@ const
   LF = #$0A;
   CRLF = CR + LF;
 
-function Quote(const Str: String): String;
+function Quote(const Str: string): string;
 begin
   Result := AnsiQuotedStr(Str, QuoteStr);
 end;
 
-function Dequote(const QuotedStr: String): String;
+function Dequote(const QuotedStr: string): string;
 begin
-  Result := QuotedStr;
-  
-  if ((AnsiStrScan(PChar(QuotedStr), QuoteStr) = QuotedStr) and (AnsiStrRScan(PChar(QuotedStr), QuoteStr) = QuoteStr)) then
-    Result := Copy(QuotedStr, 2, Length(QuotedStr) - 2);
+  Result := AnsiDequotedStr(QuotedStr, QuoteStr);
 end;
 
 function fwriteex(F, S: PChar; Un, Len: Integer; L, Dummy: Integer): Integer;
+
 var
   Size: Integer;
 begin
@@ -189,7 +187,7 @@ end;
 
 function fputsex(const F, S: String; L, Dummy: Integer): Integer;
 begin
-  Result := fwriteex(PChar(F), PChar(S), SizeOf(Char), Length(S), L, Dummy);
+  Result := fwriteex(PChar(F), PChar(S), SizeOf(Char), L, Length(S), Dummy);
 end;
 
 function fputs(const S: string; Dummy: Integer): Integer;
@@ -266,9 +264,10 @@ begin
 end;
 
 function lua_io_writeex(L: Plua_State): Integer; cdecl;
+
   function pushresult(L: Plua_State; I: Boolean; FileName: PChar): Integer;
   begin
-    lua_pushboolean(L, True);
+    lua_pushboolean(L, 1);
     Result := 1;
   end;
 const
@@ -310,9 +309,10 @@ begin
 end;
 
 function lua_io_write(L: Plua_State): Integer; cdecl;
+
   function pushresult(L: Plua_State; I: Boolean; FileName: PChar): Integer;
   begin
-    lua_pushboolean(L, True);
+    lua_pushboolean(L, 1);
     Result := 1;
   end;
 const
@@ -347,12 +347,12 @@ end;
 
 function LuaToBoolean(L: PLua_State; Index: Integer): Boolean;
 begin
-  Result := (lua_toboolean(L, Index) <> False);
+  Result := (lua_toboolean(L, Index) <> 0);
 end;
 
 procedure LuaPushBoolean(L: PLua_State; B: Boolean);
 begin
-  lua_pushboolean(L, B);
+  lua_pushboolean(L, Integer(B));
 end;
 
 function LuaToInteger(L: PLua_State; Index: Integer): Integer;
@@ -464,7 +464,7 @@ end;
 function LuaGetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string): Boolean;
 begin
   LuaGetTable(L, TableIndex, Key);
-  Result := (lua_toboolean(L, -1) <> False);
+  Result := (lua_toboolean(L, -1) <> 0);
   lua_pop(L, 1);
 end;
 
@@ -518,7 +518,7 @@ end;
 function LuaRawGetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string): Boolean;
 begin
   LuaRawGetTable(L, TableIndex, Key);
-  Result := (lua_toboolean(L, -1) <> False);
+  Result := (lua_toboolean(L, -1) <> 0);
   lua_pop(L, 1);
 end;
 
@@ -569,7 +569,7 @@ end;
 procedure LuaSetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string; B: Boolean);
 begin
   LuaPushKeyString(L, TableIndex, Key);
-  lua_pushboolean(L, B);
+  lua_pushboolean(L, Integer(B));
   lua_settable(L, TableIndex);
 end;
 
@@ -621,6 +621,17 @@ begin
   end;
 end;
 
+procedure LuaSetTablePropertyFuncs(L: PLua_State; TableIndex: Integer;
+                                   ReadFunc: lua_CFunction;
+                                   WriteFunc: lua_CFunction =nil);
+begin
+     if assigned(ReadFunc)
+     then LuaSetMetaFunction(L, TableIndex, '__index', ReadFunc);
+
+     if assigned(WriteFunc)
+     then LuaSetMetaFunction(L, TableIndex, '__newindex', WriteFunc);
+end;
+
 procedure LuaRawSetTableValue(L: PLua_State; TableIndex: Integer; const Key: string; ValueIndex: Integer);
 begin
   TableIndex := LuaAbsIndex(L, TableIndex);
@@ -640,7 +651,7 @@ end;
 procedure LuaRawSetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string; B: Boolean); 
 begin
   LuaPushKeyString(L, TableIndex, Key);
-  lua_pushboolean(L, B);
+  lua_pushboolean(L, Integer(B));
   lua_rawset(L, TableIndex);
 end;
 
@@ -691,11 +702,11 @@ function LuaGetMetaFunction(L: Plua_State; Index: Integer; Key: string): lua_CFu
 begin
   Result := nil;
   Index := LuaAbsIndex(L, Index);
-  if not lua_getmetatable(L, Index) then
+  if (lua_getmetatable(L, Index) = 0) then
     Exit;
 
   LuaGetTable(L, -1, Key);
-  if lua_iscfunction(L, -1) then
+  if (lua_iscfunction(L, -1) <> 0) then
     Result := lua_tocfunction(L, -1);
   lua_pop(L, 2);
 end;
@@ -720,7 +731,7 @@ procedure LuaSetMetaFunction(L: Plua_State; Index: Integer; Key: string; F: lua_
 // ”­�¶‚³‚¹‚Ä‚¢‚é�B
 begin
   Index := LuaAbsIndex(L, Index);
-  if not lua_getmetatable(L, Index) then
+  if (lua_getmetatable(L, Index) = 0) then
     lua_newtable(L);
 
   LuaRawSetTableFunction(L, -1, Key, F);
@@ -733,14 +744,13 @@ end;
 // Boolean: True/False
 // stirng : "..."
 // Table  : { Key1=Value Key2=Value }
-function LuaStackToStr(L: Plua_State; Index: Integer; MaxTable: Integer; SubTableMax: Integer; CheckCyclicReferencing: Boolean; TablePtrs: TList): String;
+function LuaStackToStr(L: Plua_State; Index: Integer; MaxTable: Integer; SubTableMax: Integer): string;
 var
   pGLobalsIndexPtr: Pointer;
-  bToFree: Boolean;
 
-  function TableToStr(Index: Integer): String;
+  function TableToStr(Index: Integer): string;
   var
-    Key, Value: String;
+    Key, Value: string;
     Count: Integer;
 
   begin
@@ -748,7 +758,6 @@ var
     Count := 0;
     lua_pushnil(L);
 
-
     // Go through the current table
     while (lua_next(L, Index) <> 0) do
     begin
@@ -762,22 +771,15 @@ var
 
       // Key to string
       if lua_type(L, -2) = LUA_TNUMBER then
-        Key := '[' + Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax, CheckCyclicReferencing, TablePtrs)) + ']'
+        Key := '[' + Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax)) + ']'
       else
-        Key := Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax, CheckCyclicReferencing, TablePtrs));
+        Key := Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax));
 
       // Value to string...
       if ((Key = '_G') or (lua_topointer(L, -1) = pGLobalsIndexPtr)) then
         Value := LuaGlobalVariableStr
-      else if lua_type(L, -1) = LUA_TTABLE then
-      begin
-        if Assigned(TablePtrs) and CheckCyclicReferencing and (TablePtrs.IndexOf(lua_topointer(L, -1)) <> -1) then
-          Value := '[CYCLIC_REFERENCING_DETECTED]'
-        else
-          Value := LuaStackToStr(L, -1, MaxTable, SubTableMax, CheckCyclicReferencing, TablePtrs);
-      end
       else
-        Value := LuaStackToStr(L, -1, MaxTable, SubTableMax, CheckCyclicReferencing, TablePtrs);
+        Value := LuaStackToStr(L, -1, MaxTable, SubTableMax);
 
       if (lua_type(L, -1) = LUA_TFUNCTION) then
         Result := Result + Format('%s()=%p ', [Key, lua_topointer(L, -1)])
@@ -790,15 +792,8 @@ var
 
     Result := Result + '}';
   end;
-begin
-  bToFree := False;
-
-  if not Assigned(TablePtrs) then
-  begin
-    TablePtrs := TList.Create;
-    bToFree := True;
-  end;
 
+begin
   if (MaxTable < 0) then
     MaxTable := DefaultMaxTable;
 
@@ -812,35 +807,22 @@ begin
   LUA_TNUMBER:
     Result := Format('%g', [lua_tonumber(L, Index)]);
   LUA_TBOOLEAN:
-    Result := BoolToStr(lua_toboolean(L, Index), True);
+    Result := BoolToStr(lua_toboolean(L, Index) <> 0, True);
   LUA_TSTRING:
     Result := '"'+lua_tostring(L, Index)+'"';
   LUA_TTABLE:
   begin
     if SubTableCount < SubTableMax then
     begin
-      if Assigned(TablePtrs) and CheckCyclicReferencing and (TablePtrs.IndexOf(lua_topointer(L, Index)) <> -1) then
-      begin
-        Result := '[CYCLIC_REFERENCING_DETECTED]'
-      end
-      else
-      begin
-        if Assigned(TablePtrs) then
-          TablePtrs.Add(lua_topointer(L, Index));
-
-        SubTableCount := SubTableCount + 1;
-        Result := TableToStr(Index);
-        SubTableCount := SubTableCount - 1;
-
-        //if Assigned(TablePtrs) then
-          //TablePtrs.Delete(TablePtrs.IndexOf(lua_topointer(L, Index)));
-      end;
+      SubTableCount := SubTableCount + 1;
+      Result := TableToStr(Index);
+      SubTableCount := SubTableCount - 1;
     end
     else
       Result := '[SUB_TABLE_MAX_LEVEL_HAS_BEEN_REACHED]';
   end;
   LUA_TFUNCTION:
-    if lua_iscfunction(L, Index) then
+    if (lua_iscfunction(L, Index) <> 0) then
       Result := Format('CFUNC:%p', [Pointer(lua_tocfunction(L, Index))])
     else
       Result := Format('FUNC:%p', [lua_topointer(L, Index)]);
@@ -853,9 +835,6 @@ begin
   else
     Assert(False);
   end;
-
-  if bToFree then
-    TablePtrs.Free;
 end;
 
 procedure LuaShowStack(L: Plua_State; Caption: string);
@@ -865,12 +844,11 @@ var
 begin
   N := lua_gettop(L);
   S := '[' + Caption + ']';
-  
   for I := N downto 1 do
   begin
-    S := S + CRLF + Format('%3d,%3d:%s', [LuaAbsIndex(L, I), LuaIncIndex(L, I), LuaStackToStr(L, I, -1)]);
+    S := S + CRLF + Format('%3d,%3d:%s', [LuaAbsIndex(L, I), LuaIncIndex(L, I),
+      LuaStackToStr(L, I, -1)]);
   end;
-
   ShowMessage(S);
 end;
 
@@ -976,19 +954,16 @@ begin
   lua_pop(L, Count + 1);
 end;
 
-procedure LuaStackToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer; SubTableMax: Integer; CheckCyclicReferencing: Boolean);
+procedure LuaStackToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer = -1; SubTableMax: Integer = 99);
 var
   I: Integer;
 begin
   Lines.Clear;
-  
   for I := lua_gettop(L) downto 1 do
-  begin
-    Lines.Add(LuaStackToStr(L, I, MaxTable, SubTableMax, CheckCyclicReferencing));
-  end;
+    Lines.Add(LuaStackToStr(L, I, MaxTable, SubTableMax));
 end;
 
-procedure LuaLocalToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer; Level: Integer; SubTableMax: Integer; CheckCyclicReferencing: Boolean);
+procedure LuaLocalToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer; Level: Integer; SubTableMax: Integer);
 var
   Name: PChar;
   Index: Integer;
@@ -998,129 +973,87 @@ begin
   AR := @Debug;
   Lines.Clear;
   Index := 1;
-  
   if (lua_getstack(L, Level, AR) = 0) then
     Exit;
 
   Name := lua_getlocal(L, AR, Index);
-  
   while (Name <> nil) do
   begin
-    Lines.Values[Name] := LuaStackToStr(L, -1, MaxTable, SubTableMax, CheckCyclicReferencing);
+    Lines.Values[Name] := LuaStackToStr(L, -1, MaxTable, SubTableMax);
     lua_pop(L, 1);
     Inc(Index);
     Name := lua_getlocal(L, AR, Index);
   end;
 end;
 
-procedure LuaGlobalToStrings(L: PLua_State; Lines: TStrings; MaxTable: Integer; SubTableMax: Integer; CheckCyclicReferencing: Boolean);
+procedure LuaGlobalToStrings(L: PLua_State; Lines: TStrings; MaxTable: Integer; SubTableMax: Integer);
 begin
   lua_pushvalue(L, LUA_GLOBALSINDEX);
   LuaTableToStrings(L, -1, Lines, MaxTable, SubTableMax);
   lua_pop(L, 1);
 end;
 
-procedure LuaTableToStrings(L: Plua_State; Index: Integer; Lines: TStrings; MaxTable: Integer; SubTableMax: Integer; CheckCyclicReferencing: Boolean);
+procedure LuaTableToStrings(L: Plua_State; Index: Integer; Lines: TStrings; MaxTable: Integer; SubTableMax: Integer);
 var
   Key, Value: string;
 begin
   Index := LuaAbsIndex(L, Index);
   Lines.Clear;
+
   lua_pushnil(L);
-  
   while (lua_next(L, Index) <> 0) do
   begin
-    Key := Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax, CheckCyclicReferencing));
-    Value := LuaStackToStr(L, -1, MaxTable, SubTableMax, CheckCyclicReferencing);
+    Key := Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax));
+    Value := LuaStackToStr(L, -1, MaxTable, SubTableMax);
     Lines.Values[Key] := Value;
     lua_pop(L, 1);
   end;
 end;
 
-procedure LuaTableToVirtualTreeView(L: Plua_State; Index: Integer; VTV: TVirtualStringTree; MaxTable: Integer; SubTableMax: Integer; CheckCyclicReferencing: Boolean);
+procedure LuaTableToTreeView(L: Plua_State; Index: Integer; TV: TTreeView; MaxTable: Integer; SubTableMax: Integer);
 var
   pGLobalsIndexPtr: Pointer;
-  PtrsList: TList;
-  pTreeNodeData: PBasicTreeData;
   
   // Go through all child of current table and create nodes
-  procedure ParseTreeNode(TreeNode: PVirtualNode; Index: Integer);
+  procedure ParseTreeNode(TreeNode: TTreeNode; Index: Integer);
   var
     Key: string;
-    pData: PBasicTreeData;
-    pNode: PVirtualNode;
   begin
-    // Retreive absolute index 
     Index := LuaAbsIndex(L, Index);
-    lua_pushnil(L);
 
+    lua_pushnil(L);
     while (lua_next(L, Index) <> 0) do
     begin
-      if Assigned(TreeNode) then
-        pTreeNodeData := VTV.GetNodeData(TreeNode)
+      Key := Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax));
+      if (lua_type(L, -1) <> LUA_TTABLE) then
+        TV.Items.AddChild(TreeNode, Key + '=' + LuaStackToStr(L, -1, MaxTable, SubTableMax))
       else
-        pTreeNodeData := nil;
-
-      if (pTreeNodeData = nil) or (pTreeNodeData.sValue <> '[CYCLIC_REFERENCING_DETECTED]') then
       begin
-        Key := Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax, CheckCyclicReferencing));
-
-        if lua_type(L, -1) <> LUA_TTABLE then
+        if ((Key = '_G') or (lua_topointer(L, -1) = pGLobalsIndexPtr)) then
         begin
-          pData := VTV.GetNodeData(VTV.AddChild(TreeNode));
-          pData.sName := Key;
-          pData.sValue := LuaStackToStr(L, -1, MaxTable, SubTableMax, CheckCyclicReferencing);
+          TV.Items.AddChild(TreeNode, Key + '=[LUA_GLOBALSINDEX]')
         end
         else
         begin
-          if ((Key = '_G') or (lua_topointer(L, -1) = pGLobalsIndexPtr)) then
-          begin
-            pData := VTV.GetNodeData(VTV.AddChild(TreeNode));
-            pData.sName := Key;
-            pData.sValue := '[LUA_GLOBALSINDEX]';
-          end
-          else
+          if SubTableCount < SubTableMax then
           begin
-            pNode := VTV.AddChild(TreeNode);
-            pData := VTV.GetNodeData(pNode);
-            pData.sName := Key;
-
-            if CheckCyclicReferencing and (PtrsList.IndexOf(lua_topointer(L, -1)) <> -1) then
-              pData.sValue := '[CYCLIC_REFERENCING_DETECTED]'
-            else
-              pData.sValue := LuaStackToStr(L, -1, MaxTable, SubTableMax, CheckCyclicReferencing);
-
-            if SubTableCount < SubTableMax then
-            begin
-              if CheckCyclicReferencing then
-                PtrsList.Add(lua_topointer(L, -1));
-
-              SubTableCount := SubTableCount + 1;
-              ParseTreeNode(pNode, -1);
-              SubTableCount := SubTableCount - 1;
-
-              if not Assigned(TreeNode) then
-                PtrsList.Clear;
-            end;
+            SubTableCount := SubTableCount + 1;
+            ParseTreeNode(TV.Items.AddChild(TreeNode, Key), -1);
+            SubTableCount := SubTableCount - 1;
           end;
         end;
       end;
-
       lua_pop(L, 1);
     end;
   end;
 begin
-  PtrsList := TList.Create;
   Assert(lua_type(L, Index) = LUA_TTABLE);
-  lua_checkstack(L, SubTableMax * 3); // Ensure there is enough space on stack to work with according to user's setting
-  pGLobalsIndexPtr := lua_topointer(L, LUA_GLOBALSINDEX); // Retrieve globals index pointer for later conditions
-  VTV.BeginUpdate;
-  VTV.Clear;
+  TV.Items.BeginUpdate;
+  TV.Items.Clear;
   try
     ParseTreeNode(nil, Index);
   finally
-    VTV.EndUpdate;
-    PtrsList.Free;
+    TV.Items.EndUpdate;
   end;
 end;
 
@@ -1156,13 +1089,11 @@ begin
   Mask := lua_gethookmask(L);
   Count := lua_gethookcount(L);
   lua_sethook(L, Hook, 0, Count);
-
   if (lua_pcall(L, 0, 0, 0) = 0) then
     LuaRawGetTable(L, LUA_GLOBALSINDEX, DebugValue);
-
-  Result := LuaStackToStr(L, -1, MaxTable, MaxTable, True);
+  Result := LuaStackToStr(L, -1, MaxTable);
   lua_remove(L, -1);
-  luaL_dostring(L, DebugValue + '=nil');
+  lua_dostring(L, DebugValue + '=nil');
   lua_sethook(L, Hook, Mask, Count);
 end;
 
@@ -1261,7 +1192,7 @@ begin
   if (luaL_loadbuffer(L, PChar(Code), Length(Code), PChar(Name)) = 0) then
     Exit;
 
-  LuaProcessErrorMessage(LuaStackToStr(L, -1, -1, 99, True), Title, Line, Msg);
+  LuaProcessErrorMessage(LuaStackToStr(L, -1, -1), Title, Line, Msg);
   raise ELuaException.Create(Title, Line, Msg);
 end;
 
@@ -1286,13 +1217,19 @@ begin
   if (lua_pcall(L, NArgs, NResults, ErrFunc) = 0) then
     Exit;
 
-  LuaProcessErrorMessage(Dequote(LuaStackToStr(L, -1, -1, 99, True)), Title, Line, Msg);
+  LuaProcessErrorMessage(Dequote(LuaStackToStr(L, -1, -1)),
+    Title, Line, Msg);
   raise ELuaException.Create(Title, Line, Msg);
 end;
 
-function LuaPCallFunction(L: Plua_State; FunctionName :String; const Args: array of Variant; Results : PVariantArray; ErrFunc: Integer=0; NResults :Integer=LUA_MULTRET):Integer;
+function LuaPCallFunction(L: Plua_State; FunctionName :String;
+                          const Args: array of Variant;
+                          Results : PVariantArray;
+                          ErrFunc: Integer=0;
+                          NResults :Integer=LUA_MULTRET):Integer;
 var
    NArgs, i: Integer;
+
 begin
      //Put Function To Call on the Stack
      luaPushString(L, FunctionName);
@@ -1590,6 +1527,26 @@ begin
     lua_error(L);
 end;
 
+function LuaGetCurrentFuncName(L: Plua_State) :String;
+var
+  ar          :lua_Debug;
+
+begin
+     FillChar(ar, sizeof(ar), 0);
+     Result :='';
+
+     if (lua_getStack(L, 0, @ar) = 1)
+     then begin
+               lua_getinfo(L, 'n', @ar);
+               Result :=ar.name;
+          end;
+end;
+
+function Lua_VoidFunc(L: Plua_State): Integer; cdecl;
+begin
+     Result := 0;
+end;
+
 initialization
   DefaultMaxTable := 256;
 

+ 106 - 0
LuaEdit/LuaCore/LuaVirtualTrees.pas

@@ -0,0 +1,106 @@
+//******************************************************************************
+//***                     LUA SCRIPT DELPHI UTILITIES                        ***
+//***                                                                        ***
+//***        (c) 2006 Jean-François Goulet                                   ***
+//***                                                                        ***
+//***                                                                        ***
+//******************************************************************************
+//  File        : LuaVirtualTrees.pas
+//
+//  Description : ? 
+//
+//******************************************************************************
+//** See Copyright Notice in lua.h
+
+//Revision 0.1
+//     JF Adds :
+//             LuaTableToVirtualTreeView
+//
+
+Unit LuaVirtualTrees;
+
+interface
+
+Uses SysUtils, Classes, lua, LuaUtils, VirtualTrees;
+
+
+type
+  PBasicTreeData = ^TBasicTreeData;
+  TBasicTreeData = record
+    sName: String;
+    sValue: String;
+  end;
+
+procedure LuaTableToVirtualTreeView(L: Plua_State; Index: Integer; VTV: TVirtualStringTree; MaxTable: Integer; SubTableMax: Integer);
+
+var
+  SubTableCount: Integer;
+  SubTableCount2: Integer;
+  
+implementation  
+
+procedure LuaTableToVirtualTreeView(L: Plua_State; Index: Integer; VTV: TVirtualStringTree; MaxTable: Integer; SubTableMax: Integer);
+var
+  pGLobalsIndexPtr: Pointer;
+  
+  // Go through all child of current table and create nodes
+  procedure ParseTreeNode(TreeNode: PVirtualNode; Index: Integer);
+  var
+    Key: string;
+    pData: PBasicTreeData;
+    pNode: PVirtualNode;
+  begin
+    // Retreive absolute index 
+    Index := LuaAbsIndex(L, Index);
+
+
+    lua_pushnil(L);
+    while (lua_next(L, Index) <> 0) do
+    begin
+      Key := Dequote(LuaStackToStr(L, -2, MaxTable, SubTableMax));
+      if lua_type(L, -1) <> LUA_TTABLE then
+      begin
+        pData := VTV.GetNodeData(VTV.AddChild(TreeNode));
+        pData.sName := Key;
+        pData.sValue := LuaStackToStr(L, -1, MaxTable, SubTableMax);
+      end
+      else
+      begin
+        if ((Key = '_G') or (lua_topointer(L, -1) = pGLobalsIndexPtr)) then
+        begin
+          pData := VTV.GetNodeData(VTV.AddChild(TreeNode));
+          pData.sName := Key;
+          pData.sValue := '[LUA_GLOBALSINDEX]';
+        end
+        else
+        begin
+          pNode := VTV.AddChild(TreeNode);
+          pData := VTV.GetNodeData(pNode);
+          pData.sName := Key;
+          pData.sValue := LuaStackToStr(L, -1, MaxTable, SubTableMax);
+
+          if SubTableCount < SubTableMax then
+          begin
+            SubTableCount := SubTableCount + 1;
+            ParseTreeNode(pNode, -1);
+            SubTableCount := SubTableCount - 1;
+          end;
+        end;
+      end;
+        lua_pop(L, 1);
+    end;
+  end;
+begin
+  Assert(lua_type(L, Index) = LUA_TTABLE);
+  lua_checkstack(L, SubTableMax * 3); // Ensure there is enough space on stack to work with according to user's setting
+  pGLobalsIndexPtr := lua_topointer(L, LUA_GLOBALSINDEX); // Retrieve globals index pointer for later conditions
+  VTV.BeginUpdate;
+  VTV.Clear;
+  try
+    ParseTreeNode(nil, Index);
+  finally
+    VTV.EndUpdate;
+  end;
+end;
+
+end.

+ 194 - 159
LuaEdit/LuaCore/lauxlib.pas

@@ -1,13 +1,9 @@
 (*
-** $Id: lauxlib.pas,v 1.2 2006-10-27 03:32:17 jfgoulet Exp $
+** $Id: lauxlib.pas,v 1.3 2006-11-17 00:02:16 jfgoulet Exp $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 **
-**
-** 10/02/2006 Jean-Francois Goulet - Removed deprecated function lua_loadlib()
-**                                   for compatibility with Lua 5.1.
-** 10/02/2006 Jean-Francois Goulet - Removed deprecated function lua_dostring()
-**                                   for compatibility with Lua 5.1.
+**   Translation form C and Delphi adaptation of Code : Massimo Magnano 2006
 *)
 unit lauxlib;
 
@@ -17,72 +13,74 @@ unit lauxlib;
 
 interface
 
-uses
-  lua;
+uses lua, luaconf;
+
+
+{$ifdef LUA_COMPAT_GETN}
+function luaL_getn(L: Plua_State; t: Integer): Integer; cdecl external 'lua.dll';
+procedure luaL_setn(L: Plua_State; t: Integer; n: Integer); cdecl external 'lua.dll';
+{$else}
+function luaL_getn(L: Plua_State; t: Integer): Integer;
+procedure luaL_setn(L: Plua_State; t: Integer; n: Integer);
+{$endif}
 
+{$ifdef LUA_COMPAT_OPENLIB}
+procedure luaL_openlib(L: Plua_State; libname: PChar;
+                               R: PluaL_reg; Nup: Integer); cdecl external 'lua.dll' name 'luaI_openlib';
+{$endif}
+
+const
+     LUA_ERRFILE = (LUA_ERRERR+1);
 
 type
-  luaL_reg = record
+  luaL_Reg = record
     name: PChar;
     func: lua_CFunction;
   end;
-  PluaL_reg = ^luaL_reg;
-
-function luaL_getmetafield(L: Plua_State; Obj: Integer; const E: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-function luaL_callmeta(L: Plua_State; Obj: Integer; const E: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-function luaL_typerror(L: Plua_State; NArg: Integer; const TName: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-function luaL_argerror(L: Plua_State; NumArg: Integer; const ExtraMsg: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-function luaL_checklstring(L: Plua_State; NumArg: Integer; S: Psize_t): PChar;
-  cdecl external 'lua5.1.dll';
-function luaL_optlstring(L: Plua_State; NumArg: Integer; const Def: PChar; S: Psize_t): PChar;
-  cdecl external 'lua5.1.dll';
-function luaL_checknumber(L: Plua_State; NumArg: Integer): lua_Number;
-  cdecl external 'lua5.1.dll';
-function luaL_optnumber(L: Plua_State; NArg: Integer; Def: Lua_Number): lua_Number;
-  cdecl external 'lua5.1.dll';
-
-procedure luaL_checkstack(L: Plua_State; SZ: Integer; const Msg: PChar);
-  cdecl external 'lua5.1.dll';
-procedure luaL_checktype(L: Plua_State; NArg: Integer; T: Integer);
-  cdecl external 'lua5.1.dll';
-procedure luaL_checkany(L: Plua_State; NArg: Integer);
-  cdecl external 'lua5.1.dll';
-
-function   luaL_newmetatable(L: Plua_State; const TName: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-procedure  luaL_getmetatable(L: Plua_State; const TName: PChar);
-  cdecl external 'lua5.1.dll';
-function luaL_checkudata(L: Plua_State; UD: Integer; const TName: PChar): Pointer;
-  cdecl external 'lua5.1.dll';
-
-procedure luaL_where(L: Plua_State; LVL: Integer);
-  cdecl external 'lua5.1.dll';
-function luaL_error(L: Plua_State; const Fmt: PChar): Integer; varargs;
-  cdecl external 'lua5.1.dll';
-
-function luaL_findstring(const ST: PChar; lst: array of PChar): Integer;
-  cdecl external 'lua5.1.dll';
-
-function luaL_ref(L: Plua_State; T: Integer): Integer;
-  cdecl external 'lua5.1.dll';
-procedure luaL_unref(L: Plua_State; T: Integer; Ref: Integer);
-  cdecl external 'lua5.1.dll';
-
-function luaL_getn(L: Plua_State; T: Integer): Integer;
-  cdecl external 'lua5.1.dll';
-procedure luaL_setn(L: Plua_State; T: Integer; N: Integer);
-  cdecl external 'lua5.1.dll';
-
-function luaL_loadfile(L: Plua_State; const FileName: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-function luaL_loadbuffer(L: Plua_State; const Buff: PChar; SZ: size_t; const Name: PChar): Integer;
-  cdecl external 'lua5.1.dll';
+  PluaL_Reg = ^luaL_Reg;
+
+procedure luaI_openlib(L: Plua_State; libname: PChar;
+                       R: PluaL_reg; nup: Integer); cdecl external 'lua.dll';
+procedure luaL_register(L: Plua_State; libname: PChar;
+                        const R: PluaL_reg); cdecl external 'lua.dll';
+function luaL_getmetafield(L: Plua_State; obj: Integer; const e: PChar): Integer; cdecl external 'lua.dll';
+function luaL_callmeta(L: Plua_State; obj: Integer; const e: PChar): Integer; cdecl external 'lua.dll';
+function luaL_typerror(L: Plua_State; narg: Integer; const tname: PChar): Integer; cdecl external 'lua.dll';
+function luaL_argerror(L: Plua_State; numarg: Integer; const extramsg: PChar): Integer; cdecl external 'lua.dll';
+function luaL_checklstring(L: Plua_State; numArg: Integer; s: Psize_t): PChar; cdecl external 'lua.dll';
+function luaL_optlstring(L: Plua_State; numArg: Integer;
+                         const def: PChar; s: Psize_t): PChar; cdecl external 'lua.dll';
+function luaL_checknumber(L: Plua_State; numArg: Integer): LUA_NUMBER; cdecl external 'lua.dll';
+function luaL_optnumber(L: Plua_State; nArg: Integer; def: LUA_NUMBER): LUA_NUMBER; cdecl external 'lua.dll';
+
+function luaL_checkinteger(L: Plua_State; numArg: Integer): LUA_INTEGER; cdecl external 'lua.dll';
+function luaL_optinteger(L: Plua_State; nArg: Integer; def: LUA_INTEGER): LUA_INTEGER; cdecl external 'lua.dll';
+
+procedure luaL_checkstack(L: Plua_State; sz: Integer; const msg: PChar); cdecl external 'lua.dll';
+procedure luaL_checktype(L: Plua_State; narg, t: Integer); cdecl external 'lua.dll';
+procedure luaL_checkany(L: Plua_State; narg: Integer); cdecl external 'lua.dll';
+
+function luaL_newmetatable(L: Plua_State; const tname: PChar): Integer; cdecl external 'lua.dll';
+function luaL_checkudata(L: Plua_State; ud: Integer; const tname: PChar): Pointer; cdecl external 'lua.dll';
 
+procedure luaL_where(L: Plua_State; lvl: Integer); cdecl external 'lua.dll';
+function luaL_error(L: Plua_State; const fmt: PChar): Integer; varargs; cdecl external 'lua.dll';
 
+function luaL_checkoption(L: Plua_State; narg: Integer; def: PChar; lst: array of PChar): Integer; cdecl external 'lua.dll';
+
+function luaL_ref(L: Plua_State; t: Integer): Integer; cdecl external 'lua.dll';
+procedure luaL_unref(L: Plua_State; t: Integer; ref: Integer); cdecl external 'lua.dll';
+
+function luaL_loadfile(L: Plua_State; const fileName: PChar): Integer; cdecl external 'lua.dll';
+function luaL_loadbuffer(L: Plua_State; const buff: PChar; sz: size_t;
+                                const name: PChar): Integer; cdecl external 'lua.dll';
+function luaL_loadstring(L: Plua_State; const s: PChar): Integer; cdecl external 'lua.dll';
+
+function luaL_newstate: Plua_State; cdecl external 'lua.dll';
+
+function luaL_gsub(L: Plua_State; const s, p, r: PChar): PChar; cdecl external 'lua.dll';
+
+function luaL_findtable(L: Plua_State; idx: Integer; const fname: PChar; szhint: Integer): PChar; cdecl external 'lua.dll';
 
 (*
 ** ===============================================================
@@ -93,10 +91,23 @@ function luaL_loadbuffer(L: Plua_State; const Buff: PChar; SZ: size_t; const Nam
 function luaL_argcheck(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar): Integer;
 function luaL_checkstring(L: Plua_State; N: Integer): PChar;
 function luaL_optstring(L: Plua_State; N: Integer; const D: PChar): PChar;
-function luaL_checkint(L: Plua_State; N: Integer): Integer;
-function luaL_checklong(L: Plua_State; N: Integer): Integer;
-function luaL_optint(L: Plua_State; N: Integer; D: Lua_Number): Integer;
-function luaL_optlong(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+function luaL_checkint(L: Plua_State; narg: Integer): Integer;
+function luaL_optint(L: Plua_State; narg: Integer; D: Integer): Integer;
+function luaL_checklong(L: Plua_State; narg: Integer): LongInt;
+function luaL_optlong(L: Plua_State; narg: Integer; d: Longint): Longint;
+
+function luaL_typename(L: Plua_State; i: Integer): PChar;
+
+function luaL_dofile(L: Plua_State; fn :PChar): Integer;
+
+function luaL_dostring(L: Plua_State; s :PChar): Integer;
+
+procedure luaL_getmetatable(L: Plua_State; const TName: PChar);
+
+type
+    luaL_optFunction = function (L: Plua_State; n :Integer): Integer; cdecl;
+
+function luaL_opt(L: Plua_State; f: luaL_optFunction; n, d :Integer): Integer;
 
 (*
 ** {======================================================
@@ -104,180 +115,204 @@ function luaL_optlong(L: Plua_State; N: Integer; D: Lua_Number): Integer;
 ** =======================================================
 *)
 
-
-{$IFNDEF BUFSIZ}
-const
-  BUFSIZ = 1024;
-{$ENDIF}
-
-{$IFNDEF LUAL_BUFFERSIZE}
-const
-  LUAL_BUFFERSIZE = BUFSIZ;
-{$ENDIF}
-
 type
   luaL_Buffer = record
-    P: PChar;    (* current position in buffer *)
+    p: PChar;    (* current position in buffer *)
     lvl: Integer; (* number of strings in the stack(level) *)
     L: Plua_State;
     buffer: array [0..LUAL_BUFFERSIZE - 1] of Char;
   end;
   PluaL_Buffer = ^luaL_Buffer;
 
-procedure luaL_putchar(B: PluaL_Buffer; C: Char);
+procedure luaL_addchar(B: PluaL_Buffer; c: Char);
+
+(* compatibility only *)
+procedure luaL_putchar(B: PluaL_Buffer; c: Char);
 
 function luaL_addsize(B: PLuaL_Buffer; N: Integer): PChar;
 
-procedure luaL_buffinit(L: Plua_State; B: PluaL_Buffer);
-  cdecl external 'lua5.1.dll';
-function luaL_prepbuffer(B: PluaL_Buffer): PChar;
-  cdecl external 'lua5.1.dll';
-procedure luaL_addlstring(B: PluaL_Buffer; const S: PChar; L: size_t);
-  cdecl external 'lua5.1.dll';
-procedure luaL_addstring(B: PluaL_Buffer; const S: PChar);
-  cdecl external 'lua5.1.dll';
-procedure luaL_addvalue(B: PluaL_Buffer);
-  cdecl external 'lua5.1.dll';
-procedure luaL_pushresult(B: PluaL_Buffer);
-  cdecl external 'lua5.1.dll';
+procedure luaL_buffinit(L: Plua_State; B: PluaL_Buffer); cdecl external 'lua.dll';
+function luaL_prepbuffer(B: PluaL_Buffer): PChar; cdecl external 'lua.dll';
+procedure luaL_addlstring(B: PluaL_Buffer; const s: PChar; l: size_t); cdecl external 'lua.dll';
+procedure luaL_addstring(B: PluaL_Buffer; const s: PChar); cdecl external 'lua.dll';
+procedure luaL_addvalue(B: PluaL_Buffer); cdecl external 'lua.dll';
+procedure luaL_pushresult(B: PluaL_Buffer); cdecl external 'lua.dll';
+
+function lua_dofile(L: Plua_State; const FileName: PChar): Integer;
+function lua_dostring(L: Plua_State; const Str: PChar): Integer;
+function lua_dobuffer(L: Plua_State; const Buff: PChar; SZ: size_t;
+                      const N: PChar): Integer;
 
 
 (* }====================================================== *)
 
 
 
-(*
-** Compatibility macros and functions
-*)
+(* Compatibility with ref system *)
+const
+     LUA_NOREF = -2;
+     LUA_REFNIL = -1;
 
-function lua_dofile(L: Plua_State; const FileName: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-function lua_dobuffer(L: Plua_State; const Buff: PChar; SZ: size_t;
-                               const N: PChar): Integer;
-  cdecl external 'lua5.1.dll';
-
-function luaL_check_lstr(L: Plua_State; NumArg: Integer; S: Psize_t): PChar;
-function luaL_opt_lstr(L: Plua_State; NumArg: Integer;
-                                           const Def: PChar; S: Psize_t): PChar;
-function luaL_check_number(L: Plua_State; NumArg: Integer): lua_Number;
-function luaL_opt_number(L: Plua_State; NArg: Integer; Def: Lua_Number): lua_Number;
-procedure luaL_arg_check(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar);
-function luaL_check_string(L: Plua_State; N: Integer): PChar;
-function luaL_opt_string(L: Plua_State; N: Integer; const D: PChar): PChar;
-function luaL_check_int(L: Plua_State; N: Integer): Integer;
-function luaL_check_long(L: Plua_State; N: Integer): Integer;
-function luaL_opt_int(L: Plua_State; N: Integer; D: Lua_Number): Integer;
-function luaL_opt_long(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+function lua_ref(L: Plua_State; lock: Boolean): Integer;
+
+procedure lua_unref(L: Plua_State; ref: Integer);
+
+procedure lua_getref(L: Plua_State; ref: Integer);
 
 implementation
 
+
+{$ifndef LUA_COMPAT_GETN}
+function luaL_getn(L: Plua_State; t: Integer): Integer;
+begin
+     Result :=lua_objlen(L, t)
+end;
+
+procedure luaL_setn(L: Plua_State; t: Integer; n: Integer);
+begin
+end;
+{$endif}
+
+(*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*)
+
 function luaL_argcheck(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar): Integer;
 begin
- Result := 0;
- if(not Cond) then
-   Result := luaL_argerror(L, NumArg, ExtraMsg)
+     Result := 0;
+     if not(Cond)
+     then Result := luaL_argerror(L, NumArg, ExtraMsg)
 end;
 
 function luaL_checkstring(L: Plua_State; N: Integer): PChar;
 begin
-  Result := luaL_checklstring(L, N, nil);
+     Result := luaL_checklstring(L, N, nil);
 end;
 
 function luaL_optstring(L: Plua_State; N: Integer; const D: PChar): PChar;
 begin
-  Result := luaL_optlstring(L, N, D, nil);
+     Result := luaL_optlstring(L, N, D, nil);
 end;
 
-function luaL_checkint(L: Plua_State; N: Integer): Integer;
+function luaL_checkint(L: Plua_State; narg: Integer): Integer;
 begin
-  Result := Trunc(luaL_checknumber(L, N));
+     Result := luaL_checkinteger(L, narg);
 end;
 
-function luaL_checklong(L: Plua_State; N: Integer): Integer;
+function luaL_optint(L: Plua_State; narg: Integer; D: Integer): Integer;
 begin
-  Result := Trunc(luaL_checknumber(L, N));
+  Result := luaL_optinteger(L, narg, D);
 end;
 
-function luaL_optint(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+function luaL_checklong(L: Plua_State; narg: Integer): Longint;
 begin
-  Result := Trunc(luaL_optnumber(L, N, D));
+  Result := LongInt(luaL_checkinteger(L, narg));
+  //old code : Result := Trunc(luaL_checknumber(L, narg));
 end;
 
-function luaL_optlong(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+function luaL_optlong(L: Plua_State; narg: Integer; d: Longint): Longint;
 begin
-  Result := Trunc(luaL_optnumber(L, N, D));
+     Result := LongInt(luaL_optinteger(L, narg, D));
+  //old code : Result := Trunc(luaL_optnumber(L, narg, D));
 end;
 
-procedure luaL_putchar(B: PluaL_Buffer; C: Char);
+function luaL_typename(L: Plua_State; i: Integer): PChar;
 begin
-  if ((B.P <= @B.Buffer[High(B.Buffer)]) or (luaL_prepbuffer(B) <> #0)) then
-  begin
-    B.P^ := C;
-    Inc(B.P);
-  end;
+     Result :=lua_typename(L, lua_type(L, i));
 end;
 
-function luaL_addsize(B: PLuaL_Buffer; N: Integer): PChar;
+function luaL_dofile(L: Plua_State; fn :PChar): Integer;
 begin
-  Inc(B.P, N);
-  Result := B.P;
+     Result := luaL_loadfile(L, fn);
+     if (Result=0)
+     then Result := lua_pcall(L, 0, LUA_MULTRET, 0);
 end;
 
+function luaL_dostring(L: Plua_State; s :PChar): Integer;
+begin
+     Result := luaL_loadstring(L, s);
+     if (Result=0)
+     then Result := lua_pcall(L, 0, LUA_MULTRET, 0);
+end;
 
-function luaL_check_lstr(L: Plua_State; NumArg: Integer; S: Psize_t): PChar;
+procedure luaL_getmetatable(L: Plua_State; const TName: PChar);
 begin
-  Result := luaL_checklstring(L, NumArg, S);
+     lua_getfield(L, LUA_REGISTRYINDEX, TName);
 end;
 
-function luaL_opt_lstr(L: Plua_State; NumArg: Integer;
-                                           const Def: PChar; S: Psize_t): PChar;
+function luaL_opt(L: Plua_State; f: luaL_optFunction; n, d :Integer): Integer;
 begin
-  Result := luaL_optlstring(L, NumArg, Def, S);
+     if lua_isnoneornil(L, n)
+     then Result := d
+     else Result := f(L, n);
 end;
 
-function luaL_check_number(L: Plua_State; NumArg: Integer): lua_Number;
+(*
+** {======================================================
+** Generic Buffer manipulation
+** =======================================================
+*)
+
+procedure luaL_addchar(B: PluaL_Buffer; C: Char);
 begin
-  Result := luaL_checknumber(L, NumArg);
+     if ((B.P <= @B.Buffer[High(B.Buffer)]) or (luaL_prepbuffer(B) <> #0)) then
+     begin
+          B.P^ := C;
+          Inc(B.P);
+     end;
 end;
 
-function luaL_opt_number(L: Plua_State; NArg: Integer; Def: Lua_Number): lua_Number;
+procedure luaL_putchar(B: PluaL_Buffer; c: Char);
 begin
-  Result := luaL_optnumber(L, NArg, Def);
+     luaL_addchar(B, C);
 end;
 
-procedure luaL_arg_check(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar);
+function luaL_addsize(B: PLuaL_Buffer; N: Integer): PChar;
 begin
-  luaL_argcheck(L, Cond, NumArg, ExtraMsg);
+     Inc(B.P, N);
+     Result := B.P;
 end;
 
-function luaL_check_string(L: Plua_State; N: Integer): PChar;
+function lua_dofile(L: Plua_State; const FileName: PChar): Integer;
 begin
-  Result := luaL_checkstring(L, N);
+     Result :=luaL_dofile(L, FileName);
 end;
 
-function luaL_opt_string(L: Plua_State; N: Integer; const D: PChar): PChar;
+function lua_dostring(L: Plua_State; const Str: PChar): Integer;
 begin
-  Result := luaL_optstring(L, N, D);
+     Result :=luaL_dostring(L, Str);
 end;
 
-function luaL_check_int(L: Plua_State; N: Integer): Integer;
+function lua_dobuffer(L: Plua_State; const Buff: PChar; SZ: size_t;
+                      const N: PChar): Integer;
 begin
-  Result := luaL_checkint(L, N);
+     Result := luaL_loadbuffer(L, Buff, SZ, N);
+     if (Result=0)
+     then Result := lua_pcall(L, 0, LUA_MULTRET, 0);
 end;
 
-function luaL_check_long(L: Plua_State; N: Integer): Integer;
+(* compatibility with ref system *)
+function lua_ref(L: Plua_State; lock: Boolean): Integer;
 begin
-  Result := luaL_checklong(L, N);
+     if lock
+     then Result :=luaL_ref(L, LUA_REGISTRYINDEX)
+     else begin
+               lua_pushstring(L, 'unlocked references are obsolete');
+               lua_error(L);
+               Result :=0;
+          end;
 end;
 
-function luaL_opt_int(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+procedure lua_unref(L: Plua_State; ref: Integer);
 begin
-  Result := luaL_optint(L, N, D);
+     luaL_unref(L, LUA_REGISTRYINDEX, ref);
 end;
 
-function luaL_opt_long(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+procedure lua_getref(L: Plua_State; ref: Integer);
 begin
-  Result := luaL_optlong(L, N, D);
+     lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
 end;
 
 end.

File diff suppressed because it is too large
+ 269 - 824
LuaEdit/LuaCore/lua.pas


+ 17 - 55
LuaEdit/LuaCore/lualib.pas

@@ -1,13 +1,7 @@
 (*
-** $Id: lualib.pas,v 1.2 2006-10-27 03:32:17 jfgoulet Exp $
+** $Id: lualib.pas,v 1.3 2006-11-17 00:02:17 jfgoulet Exp $
 ** Lua standard libraries
 ** See Copyright Notice in lua.h
-**
-**
-** 10/02/2006 Jean-Francois Goulet - Removed the luaopen_loadlib declaration for
-**                                   Lua 5.1 compatibility.
-** 10/02/2006 Jean-Francois Goulet - Modified all lua_****libopen() functions to
-**                                   support in-lua calls for Lua 5.1 compatibility.
 *)
 unit lualib;
 
@@ -21,7 +15,6 @@ uses
   lua;
 
 const
-  LUA_PACKLIBNAME = 'package';
   LUA_COLIBNAME = 'coroutine';
   LUA_TABLIBNAME = 'table';
   LUA_IOLIBNAME = 'io';
@@ -31,25 +24,26 @@ const
   LUA_DBLIBNAME = 'debug';
 
 function luaopen_base(L: Plua_State): Integer;
-  cdecl external 'lua5.1.dll';
-
-function luaopen_package(L: Plua_State): Integer;
-  cdecl external 'lua5.1.dll';
+  cdecl external 'lua.dll';
 
 function luaopen_table(L: Plua_State): Integer;
-  cdecl external 'lua5.1.dll';
+  cdecl external 'lua.dll';
 
 function luaopen_io(L: Plua_State): Integer;
-  cdecl external 'lua5.1.dll';
+  cdecl external 'lua.dll';
 
 function luaopen_string(L: Plua_State): Integer;
-  cdecl external 'lua5.1.dll';
+  cdecl external 'lua.dll';
 
 function luaopen_math(L: Plua_State): Integer;
-  cdecl external 'lua5.1.dll';
+  cdecl external 'lua.dll';
 
 function luaopen_debug(L: Plua_State): Integer;
-  cdecl external 'lua5.1.dll';
+  cdecl external 'lua.dll';
+
+
+function luaopen_loadlib(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
 
 
 (* to help testing the libraries *)
@@ -60,7 +54,6 @@ function luaopen_debug(L: Plua_State): Integer;
 
 (* compatibility code *)
 function lua_baselibopen(L: Plua_State): Integer;
-function lua_packlibopen(L: Plua_State): Integer;
 function lua_tablibopen(L: Plua_State): Integer;
 function lua_iolibopen(L: Plua_State): Integer;
 function lua_strlibopen(L: Plua_State): Integer;
@@ -71,63 +64,32 @@ implementation
 
 function lua_baselibopen(L: Plua_State): Integer;
 begin
-  lua_pushcfunction(L, luaopen_base);
-  lua_pushstring(L, '');
-  lua_call(L, 1, 0);
-  Result := 1;
-end;
-
-function lua_packlibopen(L: Plua_State): Integer;
-begin
-  lua_pushcfunction(L, luaopen_package);
-  lua_pushstring(L, 'package');
-  lua_call(L, 1, 0);
-  Result := 1;
+  Result := luaopen_base(L);
 end;
 
 function lua_tablibopen(L: Plua_State): Integer;
 begin
-  lua_pushcfunction(L, luaopen_table);
-  lua_pushstring(L, 'table');
-  lua_call(L, 1, 0);
-  Result := 1;
+  Result := luaopen_table(L);
 end;
 
 function lua_iolibopen(L: Plua_State): Integer;
 begin
-  lua_pushcfunction(L, luaopen_io);
-  lua_pushstring(L, 'io');
-  lua_call(L, 1, 0);
-  Result := 1;
-
-  lua_pushcfunction(L, luaopen_os);
-  lua_pushstring(L, 'os');
-  lua_call(L, 1, 0);
-  Result := 1;
+  Result := luaopen_io(L);
 end;
 
 function lua_strlibopen(L: Plua_State): Integer;
 begin
-  lua_pushcfunction(L, luaopen_string);
-  lua_pushstring(L, 'string');
-  lua_call(L, 1, 0);
-  Result := 1;
+  Result := luaopen_string(L);
 end;
 
 function lua_mathlibopen(L: Plua_State): Integer;
 begin
-  lua_pushcfunction(L, luaopen_math);
-  lua_pushstring(L, 'math');
-  lua_call(L, 1, 0);
-  Result := 1;
+  Result := luaopen_math(L);
 end;
 
 function lua_dblibopen(L: Plua_State): Integer;
 begin
-  lua_pushcfunction(L, luaopen_debug);
-  lua_pushstring(L, 'debug');
-  lua_call(L, 1, 0);
-  Result := 1;
+  Result := luaopen_debug(L);
 end;
 
 end.

Some files were not shown because too many files changed in this diff