Thread: [F-Script-talk] Dictionary and a shell command wanted :)
Brought to you by:
pmougin
From: Giovanni G. <jj...@ob...> - 2006-08-23 20:40:07
|
Hi all, I am a very strong Squeak fan and I liked a lot FScript. I decided to use Fscript to write some small front-end script. I have two question. There is a simple way of creating an associative array? Something which will be able to do: dic at:'a' put:'aValue' ? And how is possible to execute arbitrary shell commands (something like the exec() or system() C function)? Thank you very much! -- [ [ [ JJ ] ] ] | Temi cio' che conosci, non | cio' che non conosci http://www.siforge.org | |
From: Felix F. <fe...@gm...> - 2006-08-24 08:44:39
|
> Hi all, > I am a very strong Squeak fan and I liked a lot FScript. me too :) > I decided to use Fscript to write some small front-end script. > I have two question. > There is a simple way of creating an associative array? > Something which will be able to do: > dic at:'a' put:'aValue' > ? you can use a NSMutableDictionary: > dict := NSMutableDictionary new > dict setObject: 'foo' forKey: 'bar' > dict objectForKey: 'bar' 'foo' > And how is possible to execute arbitrary shell commands (something > like the exec() or system() C function)? The cocoa-way would be to use NSTask: > task := NSTask launchedTaskWithLaunchPath:'/bin/ls' arguments: NSArray array launches /bin/ls . See http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/index.html for the glory details. Hope this helps, felix > Thank you very much! > -- > [ [ [ JJ ] ] ] | Temi cio' che conosci, non > | cio' che non conosci > http://www.siforge.org | > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > F-Script-talk mailing list > F-S...@li... > https://lists.sourceforge.net/lists/listinfo/f-script-talk -- . "Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail |
From: Philippe M. <pm...@ac...> - 2006-08-24 09:09:50
|
Le 24 ao=FBt 06 =E0 10:44, Felix Franz a =E9crit : [...] > >> And how is possible to execute arbitrary shell commands (something >> like the exec() or system() C function)? > > The cocoa-way would be to use NSTask: > >> task :=3D NSTask launchedTaskWithLaunchPath:'/bin/ls' arguments: =20 >> NSArray array > > launches /bin/ls . > > See http://developer.apple.com/documentation/Cocoa/Reference/=20 > Foundation/ObjC_classic/index.html > for the glory details. > In addition, creating an Objective-C wrapper for a function like =20 system() and loading it in F-Script (see section 11 in the F-Script =20 guide) would be trivial (if you can program in Objective-C). =20 Something like this in Objective-C: -(int)executeInShell:(NSString *)str { return system([str UTF8String]); } Best, Philippe |
From: Giovanni G. <dai...@gm...> - 2006-08-24 09:48:33
|
Thank you very much! I have poked around the Cocoa library and seems very simple to use with FScript :) Is planned some new extension to the language for creating small classes in Fscript language itself? There are FScript porting to other O.S. for instance Linux and Windows? On 8/24/06, Philippe Mougin <pm...@ac...> wrote: > > Le 24 ao=FBt 06 =E0 10:44, Felix Franz a =E9crit : > > [...] > > > > >> And how is possible to execute arbitrary shell commands (something > >> like the exec() or system() C function)? > > > > The cocoa-way would be to use NSTask: > > > >> task :=3D NSTask launchedTaskWithLaunchPath:'/bin/ls' arguments: > >> NSArray array > > > > launches /bin/ls . > > > > See http://developer.apple.com/documentation/Cocoa/Reference/ > > Foundation/ObjC_classic/index.html > > for the glory details. > > > > In addition, creating an Objective-C wrapper for a function like > system() and loading it in F-Script (see section 11 in the F-Script > guide) would be trivial (if you can program in Objective-C). > Something like this in Objective-C: > > -(int)executeInShell:(NSString *)str > { > return system([str UTF8String]); > } > > Best, > > Philippe > > > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job ea= sier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > F-Script-talk mailing list > F-S...@li... > https://lists.sourceforge.net/lists/listinfo/f-script-talk > --=20 Software Architect http://www.objectsroot.com/ Software is nothing |
From: Philippe M. <pm...@ac...> - 2006-08-24 10:06:13
|
Le 24 ao=FBt 06 =E0 11:48, Giovanni Giorgi a =E9crit : > Thank you very much! > > I have poked around the Cocoa library and seems very simple to use > with FScript :) > > Is planned some new extension to the language for creating small > classes in Fscript language itself? There is preliminary support for this, with a few limitations (no =20 call to super, access to instances variable through KVC...). A more =20 complete solution will eventually be provided. Here is a basic example where we create a new subclass of NSObject, =20 named MyClass, with three instance variables named a, b and c, and =20 define a simple method named method1: > NSObject subclass:'MyClass' instanceVariableNames:'a b c' MyClass > MyClass MyClass > MyClass setFSBlock:[:self :_cmd| 'Method ' ++ _cmd ++ ' called on ' ++ self printString] asInstanceMethod:#method1 > myInstance :=3D MyClass alloc init > myInstance method1 'Method method1 called on <MyClass: 0x4bb69c0>' Using the setFSBlock... methods you can also add methods to existing =20 Cocoa classes. For another approach, look at KFDecorator, from Ken Ferry at: http://homepage.mac.com/kenferry/software.html#KFDecorator > There are FScript porting to other O.S. for instance Linux and =20 > Windows? None that I'm aware of. Best, Philippe |
From: Giovanni G. <jj...@ob...> - 2006-08-25 19:00:26
|
On 24/ago/06, at 12:07, Philippe Mougin wrote: > >> NSObject subclass:'MyClass' instanceVariableNames:'a b c' > MyClass > >> MyClass setFSBlock:[:self :_cmd| 'Method ' ++ _cmd ++ ' called on ' > ++ self printString] asInstanceMethod:#method1 > >> myInstance := MyClass alloc init > >> myInstance method1 > 'Method method1 called on <MyClass: 0x4bb69c0>' > > Using the setFSBlock... methods you can also add methods to existing > Cocoa classes. Nice! How can access to instance variable inside methods block? I tried with (self a) without so much success. Even valueForKey: didn't work :| -- [ [ [ JJ ] ] ] | When you encounter seemingly good advice | that contradicts other seemingly good advice, http://www.siforge.org | ignore them both. Al Franken |
From: Philippe M. <pm...@ac...> - 2006-08-25 20:18:39
|
Le 25 ao=FBt 06 =E0 21:00, Giovanni Giorgi a =E9crit : > > On 24/ago/06, at 12:07, Philippe Mougin wrote: > >> >>> NSObject subclass:'MyClass' instanceVariableNames:'a b c' >> MyClass >> >>> MyClass setFSBlock:[:self :_cmd| 'Method ' ++ _cmd ++ ' called on ' >> ++ self printString] asInstanceMethod:#method1 >> >>> myInstance :=3D MyClass alloc init >> >>> myInstance method1 >> 'Method method1 called on <MyClass: 0x4bb69c0>' >> >> Using the setFSBlock... methods you can also add methods to existing >> Cocoa classes. > Nice! > How can access to instance variable inside methods block? > I tried with (self a) > without so much success. > Even valueForKey: didn't work :| Here is an example using KVC to access instance variables: > MyClass setFSBlock:[:self| self setValue:33 forKey:'a'. self =20 valueForKey:'a'] asInstanceMethod:#method1 > myInstance method1 33 --Philippe |