liberty-eiffel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Liberty-eiffel] Problem with agents


From: Paolo Redaelli
Subject: Re: [Liberty-eiffel] Problem with agents
Date: Tue, 22 Dec 2015 07:21:53 +0100
User-agent: K-9 Mail for Android

I gave a quick glance at iup documentation.
The issue is probably because each feature called foo in an Eiffel class called BAR is translated into a call like

BARfoo (void *current,..... All the argument of foo)

The reference (pointer) to Current object is passed as the first argument of the actual function implementation.

As far as I have read the callback setter in iup does not allow to pass extra arguments that will be given to the callback when invoked (gtk does and we use it to pass the address to Current).
Is there a way to store a pointer in a iup widget?

Sorry for the terse answer, I just woke up here in the old side of the ocean (pun intended) and I'm going to work.
I'll try to be more precise later



Il 22 dicembre 2015 03:09:37 CET, "Germán Arias" <address@hidden> ha scritto:
Hi all,

Well, I'm working in an Eiffel plugin to the library IUP [1]. IUP is a
multi-platform toolkit for building graphical user interfaces, is native
on Windows and on GNU/Linux use Gtk+ (or Mottif). Is MIT License.
Anyway, I'm having a problem with agents, and since I'm newbie in Eiffel
I can't figure where is the problem.

To test this I have a small example as follow:

class EXAMPLE

insert
-- This expanded class have only one routine which
-- return a shared object
IUP_INTERFACE

create {ANY}
make

feature {ANY}
make
local
gui: IUP
i: INTEGER
a: COLLECTION[IUP_WIDGET]
l: IUP_LABEL
b: IUP_BUTTON
v: IUP_VBOX
w: IUP_DIALOG
do
-- The returned object is a shared object
-- created with a once routine
gui := iup_open

create l.label("Hello world from Liberty Eiffel!")
create b.button("OK", "ACTION")
gui.iup_set_callback(b, "ACTION", agent display)
a := {ARRAY[IUP_WIDGET] 0, << l, b >>}

create v.vbox(a)
create w.dialog(v)
gui.set_attribute(w, "TITLE", "Hello world")
gui.set_attribute(v, "ALIGNMENT", "ACENTER")
gui.set_attribute(v, "GAP", "10")
gui.set_attribute(v, "MARGIN", "10x10")

i := w.show

gui.iup_main
end

display
do
io.put_string("Executed %N")
end
end


Almost all widgets inherit from a class like this (reference class):


feature {ANY}
widget_pointer: POINTER
cb_action: ROUTINE[TUPLE]

widget: POINTER
do
Result := widget_pointer
end

set_widget (wgt: POINTER)
do
widget_pointer := wgt
end

set_cb_action (act: ROUTINE[TUPLE])
do
cb_action := act
end

execute_action
do
cb_action.call([])
end
end

I need store internally the agents because the IUP interface don't let
me pass user data into callbacks.

The shared object (mentioned avobe) have routines to handle callbacks,
like these (this is a reference class):

feature {ANY} -- Commands to handle callbacks
wer: IUP_WIDGET

iup_set_callback (wgt: IUP_WIDGET; name: STRING; callback:
ROUTINE[TUPLE])
do
wer := wgt
wgt.set_cb_action(callback)

int_set_callback(wgt.widget, name.to_external)

-- This call work here
-- wer.execute_action
end

int_set_callback (object: POINTER; name: POINTER)
external "plug_in"
alias "{
location: "."
module_name: "iup"
feature_name: "set_callback"
}"
end

launch_routine (obj: POINTER): INTEGER
do
wer.execute_action
Result := 1
end

For the moment I keep the widget in "wer", but of course I will change
this. The problem is with the agent, stored in the widget with
"wgt.set_cb_action(callback)". If I execute this agent, as shown the
commented lines, this works. But don't work later in "launch_routine".
"launche_routine" is executed by a external call. The program crash here
when try to execute the stored agent. Here the backtrace:


Line : 64 column 8
in /home/german/Instalados/tests/liberty/iup_test/auxiliary/iup.e.
*** Error at Run Time ***: Invalid type for the target of this procedure
call.
4 frames in run-time stack.
==== Bottom of run-time stack ====
<system root>
Current = EXAMPLE#0x24f57b8
line 10 column 4
file /home/german/Instalados/tests/liberty/iup_test/example.e


make EXAMPLE
Current = EXAMPLE#0x24f57b8
gui = IUP#0x27429e8
[ wer = #0x274d278
]
i = 0
a = ARRAY[IUP_WIDGET]#0x2751c88
[ storage = NATIVE_ARRAY[IUP_WIDGET]#0x2753cb0
lower = 0
generation = 1
capacity = 2
upper = 1
]
l = IUP_LABEL#0x274aa28
[ cb_action = Void
widget_pointer = POINTER#0x274ca10
]
b = IUP_BUTTON#0x274d278
[ cb_action = #0x274fc78
widget_pointer = POINTER#0x274f260
]
v = IUP_VBOX#0x275bca8
[ cb_action = Void
widget_pointer = POINTER#0x275dc90
]
w = IUP_DIALOG#0x275e4a8
[ cb_action = Void
widget_pointer = POINTER#0x2760490
]
line 36 column 14
file /home/german/Instalados/tests/liberty/iup_test/example.e


External call (may be a -cecil call).


launch_routine IUP
Current = IUP#0x274f260
[ wer = #0x26c3270
]
obj = POINTER#0x7f7c07ada265
Result = 0
line 64 column 8
file /home/german/Instalados/tests/liberty/iup_test/auxiliary/iup.e
==== Top of run-time stack ====
Line : 64 column 8
in /home/german/Instalados/tests/liberty/iup_test/auxiliary/iup.e.
*** Error at Run Time ***: Invalid type for the target of this procedure
call.



What is wrong? Any advice? I attached an image that show how looks this
basic example.

Germán

[1] http://webserver2.tecgraf.puc-rio.br/iup/


-- Inviato dal mio cellulare Android con K-9 Mail.
reply via email to

[Prev in Thread] Current Thread [Next in Thread]