lua-users home
lua-l archive

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


Hmm.... Oddly this still returns the same exception.  I'm using Lua
5.0.2 if that makes any difference.

Source in Delphi or C/C++:
  lua_newtable(L); // Create the table
  tbl = lua_gettop(L); // get the reference
  lua_pushstring(L, 'Params'); // place the table name on the stack
  lua_pushvalue(L, tbl); // place the table reference on the stack
  lua_settable(L, LUA_GLOBALSINDEX); // link them and make the
environment aware of them
  lua_pushnumber(L, 1); // push index on the stack
  lua_pushstring(L, 'Value 1'); // push value on the stack
  lua_settable(L, tbl); // link to our table
  lua_pushnumber(L, 2);  // push another index on the stack
  lua_pushstring(L, 'Value 2'); // push another value for the index
  lua_settable(L, tbl); // link to table

then in my lua script:
  function Test(v, k) -- prototype method
    print(v..' '..k.."\n") -- I know I could use print directly, but my
actual method does more
  end
  table.foreach(Params, Test) -- run test for each name/value pair in
table

In theory my output should be:
  1 Value 1
  2 Value 2

 - Jeremy

"Help I suffer from the oxymoron Corporate Security."


> -------- Original Message --------
> Subject: Re: Problems with creating a table from backend
> From: Matt Campbell <mattc@freedombox.cc>
> Date: Thu, April 13, 2006 12:36 pm
> To: Lua list <lua@bazar2.conectiva.com.br>
> 
> Is the second procedure from your original message supposed to leave the 
> table that it creates on the Lua stack?  If so, then take out the 
> lua_remove() function call that I gave you.
> 
> -- 
> Matt Campbell
> Lead Programmer
> Serotek Corporation
> www.freedombox.info
> "The Accessibility Anywhere People"