lua-users home
lua-l archive

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


In my luaopen_xxx function, I'm using

  const struct luaL_Reg myLib[] = { . . . }l
  lua_createtable(L,0,(sizeof(myLib)/sizeof(const struct luaL_Reg))-1);
  luaL_register(L,0,myLib);
  return 1;

That puts my functions in the module that I'm working on. I'd like to add strings to the table and am not sure how to proceed.

To add a value to a table, I have been

  lua_newtable(L);
  lua_pushstring(L,"version");
  lua_pushstring(L,"0.1");
  lua_settable(L,-3);

Does this play well with lua_createtable? Could I just do this?

  const struct luaL_Reg myLib[] = { . . . }l
  lua_createtable(L,0,(sizeof(myLib)/sizeof(const struct luaL_Reg))-1);
  luaL_register(L,0,myLib);

  lua_pushstring(L,"version");
  lua_pushstring(L,"0.1");
  lua_settable(L,-3);

  return 1;

Thanks,
Mike