lua-users home
lua-l archive

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


Thanks for the heads up Andrew. I managed to get it to work using `lua_keyin`.

As a side note, I will point out that if this is the direction the Lua team is taking, it might be prudent to reduce the amount of function calls and repeat-work that comes from searching for a key + getting its value. A function such as

     int lua_keyvalue(lua_State* int index);

would be great (though the name needs to be properly bikeshed). The desire to push the value of the key if the key is present and return non-zero: otherwise, return 0 and push nothing. This would prevent having to perform a double lookup from doing lua_keyin + lua_geti/lua_getfield/lua_gettable. This does not mean `lua_keyin` should not exist; having both would be critical to making sure the minimal amount of overhead is performed for the desired operation (checking if something exists versus knowing you are going to operate on it if it does exist).

     Just musings, but... I hope they get in, and I hope that `lua_keyin` as well as the potential hypothetical `lua_keyvalue` include versions that get integers and fields for number / string arguments directly (as well as their raw version), making for a full suite that allows maximum performance and mimics the current Lua C API structure:

     lua_keyin(L, index); lua_keyin_i(L, index, integer); lua_keyin_field(L, index, "string");
     lua_keyvalue(L, index);  lua_keyvalue_i(L, index, integer); lua_keyvalue_field(L, index, "string");



On Mon, May 28, 2018 at 2:05 PM, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
>>>>> "ThePhD" == ThePhD  <jm3689@columbia.edu> writes:

 ThePhD> I have so far successfully avoided calling rawlen / the length
 ThePhD> operator to count the number in a sequence from the C API. What
 ThePhD> do I do to know if I'm at the end of a sequence in Lua 5.4 with
 ThePhD> "LUA_NILINTABLES"? Am I missing an API function added to
 ThePhD> 5.4-work1's manual for this?

The new functions lua_keyin and lua_removekey seem not to be documented
in the manual, probably on account of the fact that NILINTABLES is still
a purely experimental feature and not going to be enabled by default,
and therefore the API for extra functions to handle it is presumably not
yet nailed down.

I notice that lua_keyin and lua_removekey both call metamethods, and I
don't see any "raw" equivalent; that could be a serious problem.

(It's obviously important that these APIs _do_ get nailed down and
documented even if NILINTABLES remains off by default)

--
Andrew.