lua-users home
lua-l archive

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


I've been playing around with wrapping Delphi classes in Lua. 
Everything seems to work fine except that LUA throws an exception when
I call one of my wrapped methods.  I'd try to give this in C, but my
skills are just too rusty so I hope others can see the problem even if
its not in your lang of choice :).

I have created my wrapper using:

inst := TLUAObject.Create(nil);
inst.InstanciateFromLUA(L);

LuaSetTableLightUserData(L, 1, HandleStr, inst);
LuaSetMetaFunction(L, 1, '__index', Lua_instIndex);
LuaSetMetaFunction(L, 1, '__newindex', Lua_instNewIndex);
result := 1


Now everything works fine for Lua_instIndex and for that matter as long
as I'm not working with a method everything works fine for
Lua_instNewIndex, but when I try and work with a method called using
Instance:Method() I get an error from lua: Attempt to call method
'MethodName' (a number value)

Everything works fine, the code in the object executes and the objects
pointer and self reference are correct, so it looks like some how I'm
not telling LUA that I handled it properly.  Any ideas?

I can try an put together a small sample application if that would help.
 Below is my code for Index also, as it may give some insight.

function instIndex(L: Plua_State): integer; cdecl;
var
  exMethod : String;
  m        : TMethod;
  s        : TObject;
  v        : Variant;
begin
  exMethod := lua_tostring(L, 2);
  s := GetInstance(L, 1);
  result := 1;
  if IsPublishedProp(s, exMethod) then
    begin
      v := GetPropValue(s, exMethod, false);
      LuaPushVariant(L, v);
    end
  else
    begin
      m.Data := s;
      m.Code := s.ClassType.MethodAddress(exMethod);
      if Assigned(m.Code) then
        result := TLuaObjectMethod(m)(l)
      else
        result := 0;
    end;
end;

 - Jeremy

"Help I suffer from the oxymoron Corporate Security."