[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Can userdate have references to lua objects?
- From: Peter Shook <pshook@...>
- Date: Sun, 11 May 2003 18:23:28 -0400
And if you like everything written in C
static int CreateFont(lua_State *L) {
gfx_createfont(L);
lua_pushvalue(L, -1); /* font */
lua_pushvalue(L, 1); /* bmp */
lua_rawset(L, lua_upvalueindex(1)); /* refs[font]=bmp */
return 1;
}
and register it like so:
lua_pushliteral(L, "CreateFont");
lua_newtable(L); /* refs table for closure */
lua_pushvalue(L, -1); /* table is its own metatable */
lua_setmetatable(L, -2);
lua_pushliteral(L, "__mode");
lua_pushliteral(L, "k");
lua_rawset(L, -3); /* metatable.__mode = "k" */
lua_pushcclosure(L, CreateFont, 1);
lua_settable(L, LUA_GLOBALSINDEX);
- Peter Shook