static Widget Realize(lua_State *L, int parentObj, Widget parent, const char *name) { Arg args[MAXARGS]; WidgetClass class; Widget widget; XmString s; struct cb_data *cbd; char nam[64], *nm; int n, narg, t; const char *cb; const char *func; widget = NULL; narg = 0; lua_pushstring(L, "__widgetClass"); lua_rawget(L, -2); class = (WidgetClass)lua_topointer(L, -1); lua_pop(L, 1); if (class != NULL) { t = lua_gettop(L); lua_pushnil(L); while (lua_next(L, t) != 0) { switch (lua_type(L, -2)) { case LUA_TSTRING: strlcpy(nam, lua_tostring(L, -2), sizeof nam); break; case LUA_TNUMBER: snprintf(nam, sizeof n, "%.f", lua_tonumber(L, -2)); break; default: strlcpy(nam, name, sizeof nam); } switch (lua_type(L, -1)) { case LUA_TSTRING: XtSetArg(args[narg], nm, lua_tostring(L, -1)); narg++; break; case LUA_TNUMBER: nm = strdup(nam); XtSetArg(args[narg], nm, (XtArgVal) (int)lua_tonumber(L, -1)); narg++; break; case LUA_TBOOLEAN: nm = strdup(nam); XtSetArg(args[narg], nm, (XtArgVal) (int)lua_toboolean(L, -1)); narg++; break; } lua_pop(L, 1); } } if (class == xmDialogShellWidgetClass) widget = XtCreatePopupShell(name, class, parent, args, narg); else if (class != NULL) widget = XtCreateManagedWidget(name, class, parent, args, narg); if (widget != NULL) { lua_pushlightuserdata(L, widget); lua_setfield(L, -2, "__widget"); luaL_getmetatable(L, WIDGET_METATABLE); lua_setmetatable(L, -2); } t = lua_gettop(L); lua_pushnil(L); while (lua_next(L, t) != 0) { switch (lua_type(L, -2)) { case LUA_TSTRING: strlcpy(nam, lua_tostring(L, -2), sizeof nam); break; case LUA_TNUMBER: snprintf(nam, sizeof n, "%.f", lua_tonumber(L, -2)); break; default: strlcpy(nam, name, sizeof nam); } switch (lua_type(L, -1)) { case LUA_TTABLE: if (widget == NULL) CreateWidgetHierarchy(L, t, parent, nam); else CreateWidgetHierarchy(L, t, widget, nam); break; case LUA_TFUNCTION: if (widget == NULL) break; cbd = malloc(sizeof(struct cb_data)); if (cbd == NULL) luaL_error(L, "memory error"); cbd->L = L; lua_pushvalue(L, -1); cbd->ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_pushvalue(L, t); cbd->obj = luaL_ref(L, LUA_REGISTRYINDEX); XtAddCallback(widget, nam, lm_Callback, cbd); XtAddCallback(widget, XmNdestroyCallback, lm_DestroyCallback, cbd); break; } lua_pop(L, 1); } for (n = 0; n < narg; n++) free(args[n].name); if (parentObj > 0) { lua_pushvalue(L, parentObj); lua_setfield(L, -2, "__parent"); } return widget; }