--- In iolanguage%40yahoogroups.com">iolanguage
yahoogroups.com, "baptisteheyman"
<baptisteheyman
...> wrote:
>
>
> --- In iolanguage%40yahoogroups.com">iolanguage
yahoogroups.com, Quentin Mathé
> <gnustep-quentin
> wrote:
> >
> > Le 29 oct. 06 à 12:39, baptisteheyman a écrit :
> >
> > > --- In iolanguage%40yahoogroups.com">iolanguage
yahoogroups.com, Quentin Mathé gnustep-quentin
> > > wrote:
> > > >
> > > > Le 27 oct. 06 à 19:17, Quentin Mathé a écrit :
> > >
> > > > How do I proceed to add new slots which aren't methods but rather
> > > > instance variables?
> > > >
> > > > I tried without success:
> > > >
> > > > NSObject newSubclassNamed:("Controller") do(
> > > > setTableView: := method(sender, self tableView := sender)
> > > > setWindow: := method(sender, self window := sender)
> > > > myVar := "whatever"
> > > > )
> > > >
> > > > I replaced myVar := "whatever" by a setSlot, updateSlot or newSlot
> > > > call without success either. Another thing I tried is to put in
> the
> > > > slot an NSString or a nil value rather an Io string.
> > > > Is this problem related to the fact we cannot add instance
> variables
> > > > on the fly on Objc side?
> > >
> > > I had added a method to create instance variable from Io side, but i
> > > finally removed it because i thought it could be problematic for the
> > > heritage on the Objective-C side.
> >
> > ok.
> >
> > > An Objective-C object allocates memory for its instance variables
> and
> > > its ancestors instance variables, so what would happen if you added
> an
> > > instance variable to an ancestors ? That's why categories don't
> allow
> > > extra variables either.
> >
> > But at the time you create the subclass, I think you can create
> > whatever instance variables you need and pass them by adding a new
> > parameter to newSubclassNamed. Then the runtime call in charge of
> > subclassing will take care of them. However it won't be possible to
> > create new slots/ivars later or in another way as it's common with
> > Io. What do you think?
> >
> > > To make your Io variable visible on the Objective-C side you could
> > > just add getter/setter methods.
> > >
> > > NSObject newSubclassNamed:("Controller") do(
> > > setTableView: := method(sender, self tableView := sender)
> > > setWindow: := method(sender, self window := sender)
> > > _myVar := "whatever"
> > > myVar := method(_myVar)
> > > setMyVar: := method(value, _myVar = value)
> > > )
> >
> > I will try that.
> > Another thing which might work well is… Declaring an Objc class
> named
> > AbstractController which includes ivar declartions in its interface.
> > Then calling AbstractController newSubclassNamed:("Controller") do
> > (... In this case, the outlets would be inherited from the superclass.
> >
> > I have a last question. What is the best way to link/load an Objc
> > framework? By linking it in a bundle and loading the bundle?
> >
> > Thanks,
> > Quentin.
> >
> > --
> > Quentin Mathé
> > qmathe
> >
>
> Yes, we could just add instance variables at class creation, but how
> would you access them from Io then ? We still need getter/setter methods
> so we're stuck unless we allow direct access to Objective-C instance
> variables. It is feasible, it was even implemented but it was really not
> needed, sharing methods between Io and Objective-C is sufficient.
>
> For your last question, well, i'm not sure to get what you want, do you
> want to load non GNUstep Objective-C code ? If so, bundle loading should
> do the trick, else you could hack the ObjcBridge build.io and add the
> dependsOnLib/dependsOnFramework line you need. Anyway if your code
> declare an informal protocol (not compiler enforced methods) you should
> add it at the end of IoObjcBridge.h and in
> IoObjcBridge_selectorEncoding. Do you want a standalone compiled program
> or a script like in
> http://www.etoile-project.org/etoile/blog/2006/09/io-and-gnustep.html ?
>
The _myVar := "whatever" will in fact never work that way, _myVar
being created in the proto but never added in the object itself, you
could see it as a class variable accessible through Controller _myVar,
so to add an instance variable you need an instance self, for example
in the init method
NSObject newSubclassNamed:("Controller") do(
setTableView: := method(sender, self tableView := sender)
setWindow: := method(sender, self window := sender)
init := method(self = super(init) ; self _myVar := "whatever" ;
self)
myVar := method(_myVar)
setMyVar: := method(value, _myVar = value)
)
An even better method is to add an addVariableNamed: method which
would be put in an Io/addons/ObjcBridge/io/ObjcBridge.io file
Object addVariableNamed: := method(name,
self setSlot(name, doString("method(?_" .. name .. ")"))
self setSlot("set" .. name asCapitalized .. ":",
doString("method(value, self _" .. name .. " := value ; self)"))
nil
)
Your test program would then become
NSObject newSubclassNamed:("Controller") do(
addVariableNamed:("tableView")
addVariableNamed:("window")
)
automatically creating accessor methods to two "private" variables
_tableView and _window.
Hope it was understandable 
.