lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello all, well I've managed to get my classes imported into the Lua
script just fine except for one minor problem.  It seems that my
"_Self" pointer is being stored into the Metatable instead of the
object table.  Thus when I create a new instance and it assigns "_Self"
it overrides all other instances "_Self" pointer :(.  I've attached one
of the smaller code blocks to the bottom with the hopes that anyone can
look at it and tell me where I went wrong.

I've spent all weekend trying multiple different things to get this to
work, but have yet to figure out exactly where I went wrong.  Compared
each method to the luna.h for 5.0 source and don't see a difference
(course I am probiably snow blind).

Here is my guess though; I'm using lua_setlighttableuserdata and I think
I should be using lua_setraw but have been unable to figure out how to
get this to work properly.

Code is at the end of this message, you can download the entire import
unit from: http://www.eonclash.com/LUA/DXWrappersLuaImport.pas

Thanks,
 - Jeremy

"Help I suffer from the oxymoron Corporate Security."

[CODE]

function CheckTPictureCollectionItem(L: Plua_State; Idx: Integer):
TPictureCollectionItem;
begin
  result := nil;
  if lua_type(L, Idx) = LUA_TTABLE then
    result := LuaGetTableLightUserData(L, Idx, '_Self')
  else
    luaL_typerror(L, Idx, LuaTPictureCollectionItemClassName);
end;

function new_TPictureCollectionItem(L: Plua_State): Integer; cdecl;
var
  c: TPictureCollectionItem;
begin
  if lua_type(L, 1) <> LUA_TTABLE then
    lua_remove(L, 1);
  c := TPictureCollectionItem.Create(frmMain.ilGameImages.Items);
  LuaSetTableLightUserData(L, 1, '_Self', c);
  luaL_getmetatable(L, LuaTPictureCollectionItemClassName);
  lua_setmetatable(L, -2);
  result := 1;
end;

function gc_TPictureCollectionItem(L: Plua_State): Integer; cdecl;
var
  c: TPictureCollectionItem;
begin
  c := CheckTPictureCollectionItem(L, 1);
  c.Free;
  result := 0;
end;

function index_TPictureCollectionItem(L: Plua_State): Integer; cdecl;
var
  c: TPictureCollectionItem;
  propName: string;
  v: Variant;
begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  propName := LuaToString(L, 1);
  if IsPublishedProp(c, propName) then
    begin
      v := GetPropValue(c, propName);
      LuaPushVariant(L, v);
    end
  else
    luaL_error(L, PChar('Property "' + propName + '" does not exist'));
  result := 1;
end;

function newindex_TPictureCollectionItem(L: PLua_State): Integer; cdecl;
var
  c: TPictureCollectionItem;
  propName: string;
  v: Variant;
  obj: TObject;
begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  propName := LuaToString(L, 1);
  v := LuaToVariant(L, 2);
  if IsPublishedProp(c, propName) then
    begin
      if PropIsType(c, propName, tkClass) then
        begin
          case lua_type(L, 2) of
            LUA_TTABLE:
              begin
                obj := LuaGetTableLightUserData(L, 2, '_Self')
              end;
            LUA_TNUMBER:
              begin
                obj := Pointer(luaToInteger(L, 2));
              end;
          else
            obj := nil;
          end;
          if Assigned(obj) then
            SetObjectProp(c, propName, obj)
          else
            luaL_error(L, PChar('Property "' + propName + '" expects and
object or object reference.'));
        end
      else
        SetPropValue(c, propName, v);
    end
  else
    luaL_error(L, PChar('Property "' + propName + '" does not exist'));
  result := 0;
end;

function luaTPictureCollectionItemDraw(L: Plua_State): Integer; cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  PatternIndex: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 3 then
    luaL_error(L, 'Draw expects 3 parameters (X, Y, PatternIndex).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      PatternIndex := luaToInteger(L, 3);
      c.Draw(DXSurface, X, Y, PatternIndex);
    end;
  result := 0;

end;

function luaTPictureCollectionItemStretchDraw(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  PatternIndex: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 2 then
    luaL_error(L, 'StretchDraw expects 5 parameters (Top, Left, Bottom,
Right, PatternIndex).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      c.StretchDraw(DXSurface, DestRect, PatternIndex);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawAdd(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  PatternIndex: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 3 then
    luaL_error(L, 'DrawAdd expects 6 parameters (Top, Left, Bottom,
Right, PatternIndex, Alpha).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      Alpha := luaToInteger(L, 6);
      c.DrawAdd(DXSurface, DestRect, PatternIndex, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawAddCol(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  PatternIndex: Integer;
  Color: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 4 then
    luaL_error(L, 'DrawAddCol expects 7 parameters (Top, Left, Bottom,
Right, PatternIndex, Color, Alpha).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      Color := luaToInteger(L, 6);
      Alpha := luaToInteger(L, 7);
      c.DrawAddCol(DXSurface, DestRect, PatternIndex, Color, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawAlpha(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  PatternIndex: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 3 then
    luaL_error(L, 'DrawAlpha expects 6 parameters (Top, Left, Bottom,
Right, PatternIndex, Alpha).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      Alpha := luaToInteger(L, 6);
      c.DrawAlpha(DXSurface, DestRect, PatternIndex, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawAlphaCol(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  PatternIndex: Integer;
  Color: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 4 then
    luaL_error(L, 'DrawAlphaCol expects 7 parameters (Top, Left, Bottom,
Right, PatternIndex, Color, Alpha).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      Color := luaToInteger(L, 6);
      Alpha := luaToInteger(L, 7);
      c.DrawAlphaCol(DXSurface, DestRect, PatternIndex, Color, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawSub(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  PatternIndex: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 3 then
    luaL_error(L, 'DrawSub expects 6 parameters (Top, Left, Bottom,
Right, PatternIndex, Alpha).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      Alpha := luaToInteger(L, 6);
      c.DrawSub(DXSurface, DestRect, PatternIndex, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawSubCol(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  PatternIndex: Integer;
  Color: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 4 then
    luaL_error(L, 'DrawSubCol expects 7 parameters (Top, Left, Bottom,
Right, PatternIndex, Color, Alpha).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      Color := luaToInteger(L, 6);
      Alpha := luaToInteger(L, 7);
      c.DrawSubCol(DXSurface, DestRect, PatternIndex, Color, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawRotate(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  CenterX: Double;
  CenterY: Double;
  Angle: single;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 8 then
    luaL_error(L, 'DrawRotate expects 8 parameters (X, Y, Width, Height,
PatternIndex, CenterX, CenterY, Angle).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      CenterX := lua_ToNumber(L, 6);
      CenterY := lua_ToNumber(L, 7);
      Angle := lua_ToNumber(L, 8);
      c.DrawRotate(DXSurface, X, Y, Width, Height, PatternIndex,
CenterX, CenterY, Angle);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawRotateAdd(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  CenterX: Double;
  CenterY: Double;
  Angle: single;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 9 then
    luaL_error(L, 'DrawRotateAdd expects 9 parameters (X, Y, Width,
Height, PatternIndex, CenterX, CenterY, Angle, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      CenterX := lua_ToNumber(L, 6);
      CenterY := lua_ToNumber(L, 7);
      Angle := lua_ToNumber(L, 8);
      Alpha := luaToInteger(L, 9);
      c.DrawRotateAdd(DXSurface, X, Y, Width, Height, PatternIndex,
CenterX, CenterY, Angle, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawRotateAddCol(L: Plua_State):
Integer; cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  CenterX: Double;
  CenterY: Double;
  Angle: single;
  Color: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 10 then
    luaL_error(L, 'DrawRotateAddCol expects 10 parameters (X, Y, Width,
Height, PatternIndex, CenterX, CenterY, Angle, Color, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      CenterX := lua_ToNumber(L, 6);
      CenterY := lua_ToNumber(L, 7);
      Angle := lua_ToNumber(L, 8);
      Color := luaToInteger(L, 9);
      Alpha := luaToInteger(L, 10);
      c.DrawRotateAddCol(DXSurface, X, Y, Width, Height, PatternIndex,
CenterX, CenterY, Angle, Color, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawRotateAlpha(L: Plua_State):
Integer; cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  CenterX: Double;
  CenterY: Double;
  Angle: single;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 9 then
    luaL_error(L, 'DrawRotateAlpha expects 9 parameters (X, Y, Width,
Height, PatternIndex, CenterX, CenterY, Angle, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      CenterX := lua_ToNumber(L, 6);
      CenterY := lua_ToNumber(L, 7);
      Angle := lua_ToNumber(L, 8);
      Alpha := luaToInteger(L, 9);
      c.DrawRotateAlpha(DXSurface, X, Y, Width, Height, PatternIndex,
CenterX, CenterY, Angle, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawRotateAlphaCol(L: Plua_State):
Integer; cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  CenterX: Double;
  CenterY: Double;
  Angle: single;
  Color: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 10 then
    luaL_error(L, 'DrawRotateAlphaCol expects 10 parameters (X, Y,
Width, Height, PatternIndex, CenterX, CenterY, Angle, Color, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      CenterX := lua_ToNumber(L, 6);
      CenterY := lua_ToNumber(L, 7);
      Angle := lua_ToNumber(L, 8);
      Color := luaToInteger(L, 9);
      Alpha := luaToInteger(L, 10);
      c.DrawRotateAlphaCol(DXSurface, X, Y, Width, Height, PatternIndex,
CenterX, CenterY, Angle, Color, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawRotateSub(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  CenterX: Double;
  CenterY: Double;
  Angle: single;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 9 then
    luaL_error(L, 'DrawRotateSub expects 9 parameters (X, Y, Width,
Height, PatternIndex, CenterX, CenterY, Angle, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      CenterX := lua_ToNumber(L, 6);
      CenterY := lua_ToNumber(L, 7);
      Angle := lua_ToNumber(L, 8);
      Alpha := luaToInteger(L, 9);
      c.DrawRotateSub(DXSurface, X, Y, Width, Height, PatternIndex,
CenterX, CenterY, Angle, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawRotateSubCol(L: Plua_State):
Integer; cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  CenterX: Double;
  CenterY: Double;
  Angle: single;
  Color: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 10 then
    luaL_error(L, 'DrawRotateSubCol expects 10 parameters (X, Y, Width,
Height, PatternIndex, CenterX, CenterY, Angle, Color, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      CenterX := lua_ToNumber(L, 6);
      CenterY := lua_ToNumber(L, 7);
      Angle := lua_ToNumber(L, 8);
      Color := luaToInteger(L, 9);
      Alpha := luaToInteger(L, 10);
      c.DrawRotateSubCol(DXSurface, X, Y, Width, Height, PatternIndex,
CenterX, CenterY, Angle, Color, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawWaveX(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  amp: Integer;
  Len: Integer;
  ph: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 8 then
    luaL_error(L, 'DrawWaveX expects 8 parameters (X, Y, Width, Height,
PatternIndex, amp, Len, ph).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      amp := luaToInteger(L, 6);
      Len := luaToInteger(L, 7);
      ph := luaToInteger(L, 8);
      c.DrawWaveX(DXSurface, X, Y, Width, Height, PatternIndex, amp,
Len, ph);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawWaveXAdd(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  amp: Integer;
  Len: Integer;
  ph: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 9 then
    luaL_error(L, 'DrawWaveXAdd expects 9 parameters (X, Y, Width,
Height, PatternIndex, amp, Len, ph, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      amp := luaToInteger(L, 6);
      Len := luaToInteger(L, 7);
      ph := luaToInteger(L, 8);
      Alpha := luaToInteger(L, 9);
      c.DrawWaveXAdd(DXSurface, X, Y, Width, Height, PatternIndex, amp,
Len, ph, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawWaveXAlpha(L: Plua_State):
Integer; cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  amp: Integer;
  Len: Integer;
  ph: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 9 then
    luaL_error(L, 'DrawWaveXAlpha expects 9 parameters (X, Y, Width,
Height, PatternIndex, amp, Len, ph, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      amp := luaToInteger(L, 6);
      Len := luaToInteger(L, 7);
      ph := luaToInteger(L, 8);
      Alpha := luaToInteger(L, 9);
      c.DrawWaveXAlpha(DXSurface, X, Y, Width, Height, PatternIndex,
amp, Len, ph, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawWaveXSub(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  X: Integer;
  Y: Integer;
  Width: Integer;
  Height: Integer;
  PatternIndex: Integer;
  amp: Integer;
  Len: Integer;
  ph: Integer;
  Alpha: Integer;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 9 then
    luaL_error(L, 'DrawWaveXSub expects 9 parameters (X, Y, Width,
Height, PatternIndex, amp, Len, ph, Alpha).')
  else
    begin
      X := luaToInteger(L, 1);
      Y := luaToInteger(L, 2);
      Width := luaToInteger(L, 3);
      Height := luaToInteger(L, 4);
      PatternIndex := luaToInteger(L, 5);
      amp := luaToInteger(L, 6);
      Len := luaToInteger(L, 7);
      ph := luaToInteger(L, 8);
      Alpha := luaToInteger(L, 9);
      c.DrawWaveXSub(DXSurface, X, Y, Width, Height, PatternIndex, amp,
Len, ph, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemDrawCol(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  DestRect: TRect;
  SourceRect: TRect;
  PatternIndex: Integer;
  Faded: Boolean;
  RenderType: TRenderType;
  Color: Integer;
  Specular: Integer;
  Alpha: Integer;
begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 8 then
    luaL_error(L, 'DrawCol expects 14 parameters (SourceTop, SourceLeft,
SourceBottom, SourceRight, DestTop, DestLeft, DestBottom, DestRight,
PatternIndex, Faded, RenderType, Color, Specular, Alpha).')
  else
    begin
      DestRect.Top := luaToInteger(L, 1);
      DestRect.Left := luaToInteger(L, 2);
      DestRect.Bottom := luaToInteger(L, 3);
      DestRect.Right := luaToInteger(L, 4);

      SourceRect.Top := luaToInteger(L, 5);
      SourceRect.Left := luaToInteger(L, 6);
      SourceRect.Bottom := luaToInteger(L, 7);
      SourceRect.Right := luaToInteger(L, 8);

      PatternIndex := luaToInteger(L, 9);
      Faded := luaToBoolean(L, 10);

      RenderType := TRenderType(GetEnumValue(TypeInfo(TRenderType),
luaToString(L, 11)));
      //RenderType := luaToTRenderType(L, 11);
      Color := luaToInteger(L, 12);
      Specular := luaToInteger(L, 13);
      Alpha := luaToInteger(L, 14);
      c.DrawCol(DXSurface, DestRect, SourceRect, PatternIndex, Faded,
RenderType, Color, Specular, Alpha);
    end;
  result := 0;

end;

function luaTPictureCollectionItemLoadFromFile(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;
  s: string;
begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 1 then
    luaL_error(L, 'LoadFromFile expects 1 parameter (FileName).')
  else
    begin
      s := LuaToString(L, 1);
      c.Picture.LoadFromFile(s);
    end;
  result := 0;
end;

function luaTPictureCollectionItemRestore(L: Plua_State): Integer;
cdecl;
var
  c: TPictureCollectionItem;

begin
  c := CheckTPictureCollectionItem(L, 1);
  lua_remove(L, 1);
  if lua_gettop(L) <> 0 then
    luaL_error(L, 'Restore expects no parameters.')
  else
    begin
      c.Restore();
    end;
  result := 0;

end;

procedure RegisterClassTPictureCollectionItem(LuaScript: TLUA);
var
  MetaTable,
    MethodTable,
    Methods: Integer;
begin
  lua_newtable(LuaScript.LuaState);
  Methods := lua_gettop(LuaScript.LuaState);

  luaL_newmetatable(LuaScript.LuaState,
LuaTPictureCollectionItemClassName);
  MetaTable := lua_gettop(LuaScript.LuaState);

  lua_pushstring(LuaScript.LuaState,
LuaTPictureCollectionItemClassName);
  lua_pushvalue(LuaScript.LuaState, Methods);
  lua_settable(LuaScript.LuaState, LUA_GLOBALSINDEX);

  lua_pushliteral(LuaScript.LuaState, '__metatable');
  lua_pushvalue(LuaScript.LuaState, Methods);
  lua_settable(LuaScript.LuaState, metatable);

  lua_pushliteral(LuaScript.LuaState, '__index');
  lua_pushcfunction(LuaScript.LuaState, index_TPictureCollectionItem);
  lua_settable(LuaScript.LuaState, MetaTable);

  lua_pushliteral(LuaScript.LuaState, '__newindex');
  lua_pushcfunction(LuaScript.LuaState,
newindex_TPictureCollectionItem);
  lua_settable(LuaScript.LuaState, MetaTable);

  lua_pushliteral(LuaScript.LuaState, '__gc');
  lua_pushcfunction(LuaScript.LuaState, gc_TPictureCollectionItem);
  lua_settable(LuaScript.LuaState, MetaTable);

  lua_newtable(LuaScript.LuaState);
  MethodTable := lua_gettop(LuaScript.LuaState);
  lua_pushliteral(LuaScript.LuaState, '__call');
  lua_pushcfunction(LuaScript.LuaState, new_TPictureCollectionItem);
  lua_pushliteral(LuaScript.LuaState, 'new');
  lua_pushvalue(LuaScript.LuaState, -2);
  lua_settable(LuaScript.LuaState, Methods);
  lua_settable(LuaScript.LuaState, MethodTable);
  lua_setmetatable(LuaScript.LuaState, Methods);

  lua_pushstring(LuaScript.LuaState, 'Draw');
  lua_pushcfunction(LuaScript.LuaState, luaTPictureCollectionItemDraw);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'StretchDraw');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemStretchDraw);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawAdd');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawAdd);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawAddCol');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawAddCol);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawAlpha');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawAlpha);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawAlphaCol');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawAlphaCol);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawSub');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawSub);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawSubCol');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawSubCol);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawRotate');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawRotate);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawRotateAdd');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawRotateAdd);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawRotateAddCol');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawRotateAddCol);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawRotateAlpha');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawRotateAlpha);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawRotateAlphaCol');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawRotateAlphaCol);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawRotateSub');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawRotateSub);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawRotateSubCol');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawRotateSubCol);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawWaveX');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawWaveX);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawWaveXAdd');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawWaveXAdd);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawWaveXAlpha');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawWaveXAlpha);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawWaveXSub');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawWaveXSub);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'DrawCol');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemDrawCol);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'Restore');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemRestore);
  lua_settable(LuaScript.LuaState, Methods);
  lua_pushstring(LuaScript.LuaState, 'LoadFromFile');
  lua_pushcfunction(LuaScript.LuaState,
luaTPictureCollectionItemLoadFromFile);
  lua_settable(LuaScript.LuaState, Methods);

  lua_pop(LuaScript.LuaState, 2);
end;