/** \file * \brief IUP binding for Lua 5. * * See Copyright Notice in "iup.h" */ #include #include #include #include "iup.h" #include "iupkey.h" #include #include #include "iuplua.h" #include "il.h" #include "iup_attrib.h" #include "iup_globalattrib.h" #include "iup_object.h" #include "iup_str.h" static int SaveImageAsText(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L, 1); const char *filename = luaL_checkstring(L, 2); const char *format = luaL_checkstring(L, 3); const char *name = luaL_optstring(L, 4, NULL); lua_pushboolean(L, IupSaveImageAsText(ih, filename, format, name)); return 1; } static int ImageGetHandle(lua_State *L) { const char *name = luaL_checkstring(L, 1); iuplua_pushihandle(L, IupImageGetHandle(name)); return 1; } static int Reparent(lua_State *L) { lua_pushinteger(L, IupReparent(iuplua_checkihandle(L,1), iuplua_checkihandle(L,2), iuplua_checkihandleornil(L,3))); return 1; } static int Insert(lua_State *L) { iuplua_pushihandle(L, IupInsert(iuplua_checkihandle(L,1), iuplua_checkihandleornil(L,2), iuplua_checkihandle(L,3))); return 1; } static int Append(lua_State *L) { iuplua_pushihandle(L, IupAppend(iuplua_checkihandle(L,1), iuplua_checkihandle(L,2))); return 1; } static int Destroy(lua_State *L) { Ihandle* ih = iuplua_checkihandle(L,1); IupDestroy(ih); return 0; } static int Detach(lua_State *L) { IupDetach(iuplua_checkihandle(L,1)); return 0; } static int Flush(lua_State *L) { (void)L; /* not used */ IupFlush(); return 0; } static int Version(lua_State *L) { lua_pushstring(L, IupVersion()); return 1; } static int GetAttributeHandle(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L, 1); const char *name = luaL_checkstring(L, 2); Ihandle* value = IupGetAttributeHandle(ih, name); if (!value) lua_pushnil(L); else iuplua_pushihandle(L, value); return 1; } static int GetAttributeData(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); const char *value = IupGetAttribute(ih, name); if (!value) lua_pushnil(L); else lua_pushlightuserdata(L, (void*)value); return 1; } static void iuplua_pushvalue(lua_State *L, Ihandle *ih, const char* name, const char* value) { if (!value || iupATTRIB_ISINTERNAL(name)) lua_pushnil(L); else { if (iupAttribIsNotString(ih, name)) { if (iupAttribIsIhandle(ih, name)) iuplua_pushihandle(L, (Ihandle*)value); else lua_pushlightuserdata(L, (void*)value); } else /* if (!lua_stringtonumber(L, value)) -- TODO: is this worth it? valid since Lua 5.3 */ lua_pushstring(L, value); } } static int GetAttribute (lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); const char *value = IupGetAttribute(ih, name); iuplua_pushvalue(L, ih, name, value); return 1; } static int GetAttributeId(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); int id = (int)luaL_checkinteger(L,3); const char *value = IupGetAttributeId(ih, name, id); iuplua_pushvalue(L, ih, name, value); return 1; } static int GetAttributeId2(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); int lin = (int)luaL_checkinteger(L,3); int col = (int)luaL_checkinteger(L,4); const char *value = IupGetAttributeId2(ih, name, lin, col); iuplua_pushvalue(L, ih, name, value); return 1; } static int GetAttributes(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *value = IupGetAttributes(ih); lua_pushstring(L,value); return 1; } static int GetAllDialogs(lua_State *L) { int n, i, max_n = (int)luaL_optinteger(L, 1, -1); char **names; if (max_n==0 || max_n==-1) max_n = IupGetAllDialogs(NULL, -1); names = (char **) malloc (max_n * sizeof(char *)); n = IupGetAllDialogs(names, max_n); lua_createtable(L, n, 0); for (i=0; i