[MacRuby-devel] assign value to identifier in runtime with objc codes

2009-07-26 Thread Linan Wang
Hi everybody,I'm trying to migrate from FScript to MacRuby. The problem I'm
facing now is how to assign values to variables in the macruby runtime with
objc codes. In Fscript framework, it's fairly straightforward:
setObject:forIdentifier call of FSInterpreter.
I've tried
rb_define_varible but it does not work. seems it requires
rb_objc_ocval_to_rval function call to convert the objc object to ruby
object first. Any help is appreciated. Thanks

-- 
Best regards

Linan Wang
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] assign value to identifier in runtime with objc codes

2009-07-27 Thread Linan Wang
Hi Laurent,Thanks for the explanation.
A related question: how to get the "main/self" object of the macruby
runtime?

On Mon, Jul 27, 2009 at 6:50 AM, Laurent Sansonetti
wrote:

> Hi Linan,
>
> You can't really assign a Ruby local variable from Objective-C, since Ruby
> locals are generally scoped around a particular method, but you can assign
> to an instance variable of a given object, a constant, a global variable (or
> eventually a class variable, but this is evil, don't try that).
> Additionally, you can evaluate a local variable assignment of a given
> Binding object from Objective-C, but this becomes hardcore.
>
> A simple example, setting an instance variable of an object created from a
> Ruby class from Objective-C:
>
> $ cat /tmp/t.m
> #import 
>
> int main(void)
> {
>[[MacRuby sharedRuntime] evaluateString:@"class Foo; def foo; @foo;
> end; end"];
>id obj = [NSClassFromString(@"Foo") new];
>NSLog(@"-> %@", [obj performRubySelector:@selector(foo)]);
>[obj performRubySelector:@selector(instance_variable_set:)
> withArguments: @"@foo", @"hello", nil];
>NSLog(@"-> %@", [obj performRubySelector:@selector(foo)]);
>[obj performRubySelector:@selector(instance_variable_set:)
> withArguments: @"@foo", @"world", nil];
>NSLog(@"-> %@", [obj performRubySelector:@selector(foo)]);
> }
>
> $ gcc /tmp/t.m -o /tmp/t -fobjc-gc -framework MacRuby -framework Foundation
>
> $ /tmp/t
> 2009-07-26 22:48:29.366 t[53439:903] -> 
> 2009-07-26 22:48:29.368 t[53439:903] -> hello
> 2009-07-26 22:48:29.369 t[53439:903] -> world
>
> HTH,
> Laurent
>
>
> On Jul 26, 2009, at 5:10 PM, Linan Wang wrote:
>
>  Hi everybody,
>> I'm trying to migrate from FScript to MacRuby. The problem I'm facing now
>> is how to assign values to variables in the macruby runtime with objc codes.
>> In Fscript framework, it's fairly straightforward: setObject:forIdentifier
>> call of FSInterpreter.
>> I've tried rb_define_varible but it does not work. seems it requires
>> rb_objc_ocval_to_rval function call to convert the objc object to ruby
>> object first. Any help is appreciated. Thanks
>>
>> --
>> Best regards
>>
>> Linan Wang
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>



-- 
Best regards

Linan Wang
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] assign value to identifier in runtime with objc codes

2009-07-27 Thread Linan Wang
Got it. thanks!
On Mon, Jul 27, 2009 at 7:50 PM, Laurent Sansonetti
wrote:

> Hi Linan,
> You can evaluate "self" for that.
>
> id ruby_self = [[MacRuby sharedRuntime] evaluateString:@"self"];
>
> Laurent
>
> On Jul 27, 2009, at 1:52 AM, Linan Wang wrote:
>
> Hi Laurent,Thanks for the explanation.
> A related question: how to get the "main/self" object of the macruby
> runtime?
>
> On Mon, Jul 27, 2009 at 6:50 AM, Laurent Sansonetti  > wrote:
>
>> Hi Linan,
>>
>> You can't really assign a Ruby local variable from Objective-C, since Ruby
>> locals are generally scoped around a particular method, but you can assign
>> to an instance variable of a given object, a constant, a global variable (or
>> eventually a class variable, but this is evil, don't try that).
>> Additionally, you can evaluate a local variable assignment of a given
>> Binding object from Objective-C, but this becomes hardcore.
>>
>> A simple example, setting an instance variable of an object created from a
>> Ruby class from Objective-C:
>>
>> $ cat /tmp/t.m
>> #import 
>>
>> int main(void)
>> {
>>[[MacRuby sharedRuntime] evaluateString:@"class Foo; def foo; @foo;
>> end; end"];
>>id obj = [NSClassFromString(@"Foo") new];
>>NSLog(@"-> %@", [obj performRubySelector:@selector(foo)]);
>>[obj performRubySelector:@selector(instance_variable_set:)
>> withArguments: @"@foo", @"hello", nil];
>>NSLog(@"-> %@", [obj performRubySelector:@selector(foo)]);
>>[obj performRubySelector:@selector(instance_variable_set:)
>> withArguments: @"@foo", @"world", nil];
>>NSLog(@"-> %@", [obj performRubySelector:@selector(foo)]);
>> }
>>
>> $ gcc /tmp/t.m -o /tmp/t -fobjc-gc -framework MacRuby -framework
>> Foundation
>>
>> $ /tmp/t
>> 2009-07-26 22:48:29.366 t[53439:903] -> 
>> 2009-07-26 22:48:29.368 t[53439:903] -> hello
>> 2009-07-26 22:48:29.369 t[53439:903] -> world
>>
>> HTH,
>> Laurent
>>
>>
>> On Jul 26, 2009, at 5:10 PM, Linan Wang wrote:
>>
>>  Hi everybody,
>>> I'm trying to migrate from FScript to MacRuby. The problem I'm facing now
>>> is how to assign values to variables in the macruby runtime with objc codes.
>>> In Fscript framework, it's fairly straightforward: setObject:forIdentifier
>>> call of FSInterpreter.
>>> I've tried rb_define_varible but it does not work. seems it requires
>>> rb_objc_ocval_to_rval function call to convert the objc object to ruby
>>> object first. Any help is appreciated. Thanks
>>>
>>> --
>>> Best regards
>>>
>>> Linan Wang
>>> ___
>>> MacRuby-devel mailing list
>>> [email protected]
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>
>>
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>
>
>
> --
> Best regards
>
> Linan Wang
>  ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
>
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
>


-- 
Best regards

Linan Wang
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] a snow leopard build?

2009-08-27 Thread Linan Wang
Hi,
I tried couple of hours to compile MacRuby under Snow Leopard but no
luck. Maybe someone likes to share a built copy? It would be a great
favour for those application developers like myself. Thanks!

-- 
Best regards

Linan Wang
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] a snow leopard build?

2009-08-27 Thread Linan Wang
Thanks. It seems to be the case.

On Thu, Aug 27, 2009 at 12:06 PM, Giampiero De
Ciantis wrote:
> Hi Linan,
>
> I had the same issue when I realized that I needed to re-install XCode from
> SL disk after upgrading. I don't know if you are having the same issues or
> you have already done this step, but if you are getting errors that Make
> cannot be found and things, this is most likely the cause.
>
> Cheers,
>
> -Gp
>
>
>
> On 2009-08-27, at 7:02 AM, Linan Wang wrote:
>
>> Hi,
>> I tried couple of hours to compile MacRuby under Snow Leopard but no
>> luck. Maybe someone likes to share a built copy? It would be a great
>> favour for those application developers like myself. Thanks!
>>
>> --
>> Best regards
>>
>> Linan Wang
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>



-- 
Best regards

Linan Wang
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] objc block and ruby block?

2009-09-15 Thread Linan Wang

Hi,
I'm playing with the new block syntax of objc recently. I tried to  
call a ruby block from an objc block-ish methods but failed. The code  
snippet:


@implementation BlockTest
...
-(void)testBlock:(void^(int i))block
{
   block(self.x);
}
...
@end;

MacRuby codes:

b.testBlock do |x|
  puts x
end

Anything wrong with my codes? or it's not supported yet? (if so, any  
plan to do it?)


Best wishes
Linan
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] objc block and ruby block?

2009-09-15 Thread Linan Wang

Hi Laurent,
Thanks for the reply.
I'm just playing with new functions, not on a project. It is not a  
highly demanded feature. I really appreciate your kind gesture.
I wonder if there is any quick work around, e.g. put some macruby  
related codes into the objc codes so that ruby blocks can be invoked?

Best wishes,
Linan

On 16 Sep 2009, at 01:26, Laurent Sansonetti wrote:


Hi Linan,

This is currently not implemented. It is not planned for the  
upcoming release mostly because I don't think it's that important,  
since all block methods in Cocoa also have methods dealing with  
function pointers, which will be supported.


If you have any need for such a feature we can tentatively implement  
it for the release.


Laurent

On Sep 15, 2009, at 4:28 PM, Linan Wang wrote:


Hi,
I'm playing with the new block syntax of objc recently. I tried to  
call a ruby block from an objc block-ish methods but failed. The  
code snippet:


@implementation BlockTest
...
-(void)testBlock:(void^(int i))block
{
 block(self.x);
}
...
@end;

MacRuby codes:

b.testBlock do |x|
puts x
end

Anything wrong with my codes? or it's not supported yet? (if so,  
any plan to do it?)


Best wishes
Linan
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] problem with build macruby 0.5

2009-09-26 Thread Linan Wang

Hi,
MacRuby 0.5 is currently for Snow Leopard only, and it depends upon  
specific version of llvm. I'd suggest you to download the daily built  
from http://macruby.icoretech.org/.


On 26 Sep 2009, at 23:36, sergei homjakov wrote:


 Hello! I have problem with build macruby 0.5 (command rake)

$ rake

/opt/local/bin/ruby tool/compile_prelude.rb prelude.rb  
miniprelude.c.new rm miniprelude.c.new /usr/bin/gcc -I. -I./include - 
I./onig -I/usr/include/libxml2 -arch i386 -arch x86_64 -fno-common - 
pipe -O3 -g -Wall -fexceptions -Wno-parentheses -Wno-deprecated- 
declarations -Werror -std=c99 -c prelude.c -o prelude.o cp  
miniprelude.c prelude.c /usr/bin/g++ -I. -I./include -I./onig -I/usr/ 
include/libxml2 -arch i386 -arch x86_64 -fno-common -pipe -O3 -g - 
Wall -fexceptions -Wno-parentheses -Wno-deprecated-declarations - 
Werror -std=c99 array.o bignum.o class.o compar.o complex.o enum.o  
enumerator.o error.o eval.o file.o load.o proc.o gc.o hash.o inits.o  
io.o math.o numeric.o object.o pack.o parse.o prec.o dir.o process.o  
random.o range.o rational.o re.o onig/regcomp.o onig/regext.o onig/ 
regposix.o onig/regenc.o onig/reggnu.o onig/regsyntax.o onig/ 
regerror.o onig/regparse.o onig/regtrav.o onig/regexec.o onig/ 
regposerr.o onig/regversion.o onig/enc/ascii.o onig/enc/unicode.o  
onig/enc/utf8.o onig/enc/euc_jp.o onig/enc/sjis.o onig/enc/ 
iso8859_1.o onig/enc/utf16_be.o onig/enc/utf16_le.o onig/enc/ 
utf32_be.o onig/enc/utf32_le.o ruby.o set.o signal.o sprintf.o st.o  
string.o struct.o time.o transcode.o util.o variable.o version.o  
thread.o id.o objc.o bs.o encoding.o dln.o dmyext.o marshal.o gcd.o  
vm_eval.o prelude.o bridgesupport.o compiler.o vm.o MacRuby.o -L/usr/ 
local/lib -lpthread -lffi -lm -lLLVMBitWriter -lLLVMX86CodeGen - 
lLLVMX86Info -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMJIT - 
lLLVMExecutionEngine -lLLVMCodeGen -lLLVMScalarOpts - 
lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC - 
lLLVMCore -lLLVMSupport -lLLVMSystem -lpthread -ldl -lxml2 -lobjc - 
lauto -framework Foundation -dynamiclib -undefined suppress - 
flat_namespace -install_name /Library/Frameworks/MacRuby.framework/ 
Versions/0.5/usr/lib/libmacruby.dylib -current_version 0.5 - 
compatibility_version 0.5 -o libmacruby.1.9.0.dylib ./miniruby -I. - 
I./lib bin/rubyc --internal -C "lib/net/imap.rb" -o "lib/net/ 
imap.rbo" lib/net/imap.rb:1131: premature end of char-class: /[\x80- 
\xff\r\n]/ lib/net/imap.rb:1882: end pattern in group: /\G(?:(?# 1:  
SPACE )( +)|(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\] 
+])|(?# 3: NUMBER )(\d+)(?=[\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+])|(? 
# 4: ATOM )([\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+]+)|(?# 5:  
QUOTED )"((?:[\x00\r\n"\\]|\\["\\])*)"|(?# 6: LPAR )(\()|(?# 7:  
RPAR )(\))|(?# 8: BSLASH )(\\)|(?# 9: STAR )(\*)|(?# 10: LBRA )(\[)| 
(?# 11: RBRA )(\])|(?# 12: LITERAL )\{(\d+)\}\r\n|(?# 13: PLUS )(\+)| 
(?# 14: PERCENT )(%)|(?# 15: CRLF )(\r\n)|(?# 16: EOF )(\z))/i lib/ 
net/imap.rb:2436: premature end of char-class: /[\x80-\xff\r\n]/ lib/ 
net/imap.rb:2767: end pattern with unmatched parenthesis: /\G(?# 1:  
NAME )(?:NIL|"((?:[\x80-\xff\x00\r\n"\\]|\\["\\])*)") (?# 2: ROUTE ) 
(?:NIL|"((?:[\x80-\xff\x00\r\n"\\]|\\["\\])*)") (?# 3: MAILBOX ) 
(?:NIL|"((?:[\x80-\xff\x00\r\n"\\]|\\["\\])*)") (?# 4: HOST ) 
(?:NIL|"((?:[\x80-\xff\x00\r\n"\\]|\\["\\])*)")\)/i lib/net/imap.rb: 
2831: premature end of char-class: /(?# FLAG )\\([\x80-\xff(){ \x00- 
\x1f\x7f%"\\]+)|(?# ATOM )([\x80-\xff(){ \x00-\x1f\x7f%*"\\]+)/  
unknown: [BUG] Segmentation fault MacRuby version 0.5 (ruby 1.9.0)  
[universal-darwin9.0, x86_64]


Error when executing `./miniruby --emit-llvm "/var/folders/OU/ 
OUarP1IfGbW42ZIf+RRW8E+++TI/-Tmp-/imap.bc" MREP_12163095864224378147  
"lib/net/imap.rb"' rake aborted! Command failed with status (1): -I.  
-I./lib bin/rubyc --interna...


/opt/local/bin/ruby -v

ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]

/opt/local/bin/rake --version
rake, version 0.8.7


Sergei.
Thanks.
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] implementation of symbols

2009-10-05 Thread Linan Wang

Hi,
I read a little bit source codes and found out that Symbol is  
implemented on top of NSString. My question is if it's a better choice  
to use SEL as the basis when objc is available? objc runtime takes  
care of the registration and management. I guess using NSString class  
is a decision with good reasons, could anybody please shine some  
lights on it? Thanks

Best wishes
Linan
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] implementation of symbols

2009-10-05 Thread Linan Wang

That's a quick response. I'll look into the codes. Thanks!
On 6 Oct 2009, at 01:05, Laurent Sansonetti wrote:


Hi Linan,

Actually, we do use SELs to unify symbols (if you look at parse.y).  
The Symbol class just inherits from NSString for convenience purposes.


The current code is far to be perfect but so far it works okay.

Laurent

On Oct 5, 2009, at 4:55 PM, Linan Wang wrote:


Hi,
I read a little bit source codes and found out that Symbol is  
implemented on top of NSString. My question is if it's a better  
choice to use SEL as the basis when objc is available? objc runtime  
takes care of the registration and management. I guess using  
NSString class is a decision with good reasons, could anybody  
please shine some lights on it? Thanks

Best wishes
Linan
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel