lua-users home
lua-l archive

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


What about Lua version of it?

Also lua version of unpack_table. Can be done by pushing all hash values to sequential table and then unpacking it
On 29 Mar 2022, 12:44 +0300, 云风 Cloud Wu <cloudwu@gmail.com>, wrote:
Spar <developspartv@gmail.com> 于2022年3月29日周二 17:27写道:

As universal function to unpack hash-key-values it's great. But this might be useful for specific tables structures like Color. In that case it's better to use getfield directly. This will fulfill consistent and specific use

For the table { x = 1, y = 2, z = 3, w = 4},
I test the getfield version:

static int lunpack_xyzw(lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
lua_getfield(L, 1, "x");
lua_getfield(L, 1, "y");
lua_getfield(L, 1, "z");
lua_getfield(L, 1, "w");
return 4;
}

`unpack_table` is 2x faster.

--
http://blog.codingnow.com