// %rename iswxluatype %function int wxlua_iswxluatype(int luatype, int wxluaarg_tag)
static int LUACALL wxLua_function_iswxluatype(lua_State *L)
{
    // int wxluaarg_tag
    int wxluaarg_tag = (int)wxlua_getnumbertype(L, 2);
    // int luatype
    int luatype = (int)wxlua_getnumbertype(L, 1);
    // call wxlua_iswxluatype
    int returns = (wxlua_iswxluatype(luatype, wxluaarg_tag));
    // push the result number
    lua_pushnumber(L, returns);

    return 1;
}
// %override wxLua_function_ungcobject
// %function bool ungcobject(void* object)
static int LUACALL wxLua_function_ungcobject(lua_State *L)
{
    bool ret = false;

    int l_type = lua_type(L, 1);

    if (!wxlua_iswxluatype(l_type, WXLUA_TUSERDATA))
        wxlua_argerror(L, 1, wxT("a 'userdata'"));

    void* o = wxlua_touserdata(L, 1, false);

    if (wxluaO_isgcobject(L, o))
    {
        ret = wxluaO_undeletegcobject(L, o);
    }

    lua_pushboolean(L, ret);
    return 1;
}
static bool callback(lua_State *L, int iLuaCallbackTag, unsigned long ulProgressData, void *pvCallbackUserData)
{
	bool fStillRunning;
	int iOldTopOfStack;
	int iResult;
	int iLuaType;
	wxString strMsg;


	// check lua state and callback tag
	if( L!=NULL && iLuaCallbackTag!=0 )
	{
		// get the current stack position
		iOldTopOfStack = lua_gettop(L);
		// push the function tag on the stack
		lua_rawgeti(L, LUA_REGISTRYINDEX, iLuaCallbackTag);
		// push the arguments on the stack
		lua_pushnumber(L, ulProgressData);
		lua_pushnumber(L, (long)pvCallbackUserData);
		// call the function
		iResult = lua_pcall(L, 2, 1, 0);
		if( iResult!=0 )
		{
			switch( iResult )
			{
			case LUA_ERRRUN:
				strMsg = wxT("runtime error");
				break;
			case LUA_ERRMEM:
				strMsg = wxT("memory allocation error");
				break;
			default:
				strMsg.Printf(wxT("unknown errorcode: %d"), iResult);
				break;
			}
			wxLogError(wxT("callback function failed: ") + strMsg);
			strMsg = wxString::FromAscii(wxlua_getstringtype(L, -1));
			wxLogError(strMsg);
			wxLogError(wxT("cancel operation"));
			fStillRunning = false;
		}
		else
		{
			// get the function's return value
			iLuaType = lua_type(L, -1);
			if( wxlua_iswxluatype(iLuaType, WXLUA_TBOOLEAN)==false )
			{
				wxLogError(wxT("callback function returned a non-boolean type!"));
				fStillRunning = false;
			}
			else
			{
				if( iLuaType==LUA_TNUMBER )
				{
					iResult = lua_tonumber(L, -1);
				}
				else
				{
					iResult = lua_toboolean(L, -1);
				}
				fStillRunning = (iResult!=0);
			}
		}
		// return old stack top
		lua_settop(L, iOldTopOfStack);
	}
	else
	{
		// no callback function -> keep running
		fStillRunning = true;
	}

	return fStillRunning;
}