summaryrefslogtreecommitdiff
path: root/tests/C/lua_setgettable.c
blob: af3d9f8e26588d5f0425a5ed176c38a3e2deb868 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>

int main(void) {

    lua_State *L = luaL_newstate();

    luaL_openlibs(L);

    lua_newtable(L);

    lua_pushstring(L, "key");
    lua_pushstring(L, "value");

    lua_settable(L, -3);

    lua_pushstring(L, "key");
    lua_gettable(L, -2);


    printf("L->top(%d): %s\n", lua_gettop(L), luaL_typename(L, -1));
    printf("Table has value: %s\n", lua_tostring(L, -1));

    lua_close(L);

    return 0;

}