Sorry,

In Matlab there are these two functions that allow us to store any kind of 
matlab data (a struct, a cell array, a matrix) in a container of a handle 
to a GUI object
(a button, an image, a figure ...) and later retrieve it with with 

getappdata(handles, "container_name")

I did the same with the IUP.jl <https://github.com/joa-quim/IUP.jl> (that 
you kindly visited before) C libraries. Here it's the C side that either 
gives me back the pointer to the stored data (previously stored with IUP 
istself) or the NULL pointer if the container is empty. 
I need to transfer that info back to Julia, which I do as

function getappdata(hand::Ptr{Ihandle}, name::String)
    # Do the oposite of setappdata
    att = IupGetAttribute(hand, name)
    if (att != C_NULL)
        val = unsafe_pointer_to_objref(att)
    else
        val = []
    end
    return val
end

So on the Julia side I need to be able to test if val is empty or not. The 
type of data store in 'val' is the users responsibility to know. Like in 
Matlab



segunda-feira, 19 de Janeiro de 2015 às 18:08:34 UTC, Milan Bouchet-Valat 
escreveu:
>
> Le lundi 19 janvier 2015 à 09:48 -0800, J Luis a écrit : 
> > 
> >         In Matlab, all variables are arrays, so testing for emptiness 
> >         is (nearly) always possible, although not always meaningful. 
> >         For example, what does isempty mean when applied to a file or 
> >         a window? In matlab these are simply hardcoded to be false 
> >         (not empty). 
> >         
> >         What are you trying to do? 
> > 
> > I implemented a kind of setappdata/getappdata in IUP so I need to be 
> > able to test that the container is empty or not. But I don't know in 
> > advance what kind of data was stored in the container. 
> I'm not sure I get your idea. If you know that there's a container (say, 
> an Array), then you can just call length() and check that it's not 0, 
> disregarding the type of the container's elements. 
>
> If the problem is that the user is allowed to pass a scalar instead of 
> an array, the solution is probably to forbid this, and require passing a 
> one-element array. This makes the code simpler and cleaner. 
>
> Also, "setappdata/getappdata in IUP" does not evoke much to me. Care to 
> give more details? 
>
>
> Regards 
>
>
> >         On Mon, Jan 19, 2015 at 8:42 AM J Luis <jmf...@gmail.com> 
> >         wrote: 
> >                 Thanks but again no, they all suffer from the same 
> >                 illness 
> >                 
> >                 julia> length(tp) 
> >                 ERROR: MethodError: `length` has no method matching 
> >                 length(::foo) 
> >                 
> >                 segunda-feira, 19 de Janeiro de 2015 às 13:28:39 UTC, 
> >                 Kaj Wiik escreveu: 
> >                         What about simply length()? 
> >                         
> >                         
> >                         julia> a=[] 
> >                         0-element Array{None,1} 
> >                         
> >                         
> >                         julia> length(a) 
> >                         0 
> >                         
> >                         
> >                         julia> a=[1,3] 
> >                         2-element Array{Int64,1}: 
> >                          1 
> >                          3 
> >                         
> >                         
> >                         julia> length(a) 
> >                         2 
> >                         
> >                         
> >                         
> >                         Kaj 
> >                         
> >                         
> >                         
> >                         
>
>

Reply via email to