lua-users home
lua-l archive

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


#include <lua.h>
#include <lauxlib.h>

static int close(lua_State *L) {
  return 0;
}

static void newtable(lua_State *L) {
    static const luaL_Reg mt[] = {
        {"__close", close},
        {NULL, NULL}
    };
    lua_newtable(L);
    luaL_newlib(L, mt);
    lua_setmetatable(L, -2);
}

int luaopen_toclose(lua_State *L) {
    lua_pushinteger(L, 1);
    newtable(L);
    lua_toclose(L, -1);
    lua_remove(L, -2); // throw error: attempt to close non-closable variable '?'
    return 1;
}


-- actboy168