lua-users home
lua-l archive

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


I can't believe I can't find a sample of this, but I'm having problems
creating a table that contains "settings" for a method.  Below is the
code I've tried along with comments and the exception that comes back:

procedure PushParam(L : Plua_State; PropName, PropType, PropOption:
String);
var
  ptbl : Integer;
begin
  lua_newtable(L);
  ptbl := lua_gettop(L);// get the tables index
  lua_pushstring(L, 'Name');
  lua_pushstring(L, PChar(PropName));
  lua_settable(L, ptbl); // set the name/value pair to the new table
  lua_pushstring(L, 'Type');
  lua_pushstring(L, PChar(PropType));
  lua_settable(L, ptbl); // set the name/value pair to the new table
  lua_pushstring(L, 'Option');
  lua_pushstring(L, PChar(PropOption));
  lua_settable(L, ptbl); // set the name/value pair to the new table
end;

procedure PushMethodParams(L : Plua_State);
var
  tbl : Integer;
  m : PMethodInfo;
  i : Integer;
  po: String;
begin
  lua_pushstring(L, 'Params');
  lua_newtable(L);
  tbl := lua_gettop(L);// get the table reference
  lua_settable(L, LUA_GLOBALSINDEX);//set the var name "Params" = table
instance
  m := GetActiveMethodList;
  for i := 0 to Length(m.Params)-1 do
    begin
      case m.Params[i].ParamOp of
        ptVar : po := 'Var';
        ptConst : po := 'Const';
        ptOut : po := 'Out';
      else
        po := '';
      end;
      lua_pushnumber(L, i+1);// set the table index
      PushParam(L, m.Params[i].ParamName, m.Params[i].ParamType, po);
      lua_settable(L, tbl);
    end;
end;

Calling this and watching it shows that all the values are correct.  But
when I then do an execute and try to use Params as a table I get back
the error of:
[string ""]:2: attempt to index field `?` (a nil value)(2)

Any ideas of what I'm doing wrong, as I know its something.

Thanks,
 - Jeremy

"Help I suffer from the oxymoron Corporate Security."