lua-users home
lua-l archive

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


On Thu, Jan 14, 2021 at 12:43 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> >Simply check if yourtable[yourkey] is nil
> This is a Lua script.
> How to achieve this goal(i.e the subject)  by C api?

Translate to the C API, push the table, push the key, lookup using
https://www.lua.org/manual/5.4/manual.html#lua_gettable

You may need some more movements, depending on where you have your
table and key stored, i.e., you may need something like this for
globals:

lua_getglobal(L, "yourtable"); /* Table is at -1 */
lua_getglobal(L, "yourkey"); /* Table is at -2, key at -1 */
lua_gettable(L, -2); /* Table still at -2, value at -1 */

And some error checking if you deem it neccessary.

FOS