Permalink
Browse files

Bug fix

git-svn-id: http://hotruby.googlecode.com/svn/trunk@17 4fb8041d-b042-0410-9571-f50be27af959
  • Loading branch information...
1 parent d0a12f4 commit 821c489cdf8afbd3b0482e82d926d14c21e6c818 yukoba@accelart.jp committed Jan 14, 2008
Showing with 96 additions and 28 deletions.
  1. +40 −15 src/RubyVM.js
  2. +1 −1 test/asEnv/asEnv.js
  3. +2 −2 test/asEnv/asEnv.rb
  4. +53 −10 test/asEnv/asEnv_pretty.json
View
@@ -660,10 +660,7 @@ HotRuby.prototype = {
// Invoke native method
if(op != null)
throw "[invokeNativeMethod] Unsupported operator: " + op;
- var convArgs = new Array(args.length);
- for(var i=0; i<args.length; i++) {
- convArgs[i] = this.rubyObjectToNative(args[i]);
- }
+ var convArgs = this.rubyObjectAryToNativeAry(args);
ret = recver.__native[methodName].apply(recver, convArgs);
} else {
// Get native instance variable
@@ -698,7 +695,7 @@ HotRuby.prototype = {
proc.__parentStackFrame.classObj,
proc.__parentStackFrame.methodName,
proc.__parentStackFrame.self,
- arguments,
+ hr.nativeAryToRubyObjectAry(arguments),
proc.__parentStackFrame,
true);
};
@@ -709,20 +706,48 @@ HotRuby.prototype = {
return v.__native;
},
+ /**
+ * Convert array of ruby object to array of native object
+ * @param {Array} ary Array of ruby object
+ */
+ rubyObjectAryToNativeAry: function(ary) {
+ var convAry = new Array(ary.length);
+ for(var i=0; i<ary.length; i++) {
+ convAry[i] = this.rubyObjectToNative(ary[i]);
+ }
+ return convAry;
+ },
+
/**
* Convert native object to ruby object
+ * @param v native object
*/
- nativeToRubyObject: function(ret) {
- if(typeof(ret) == "number") {
- return ret;
- } else if(typeof(ret) == "string") {
- return this.createRubyString(ret);
- } else {
- return {
- __className: "NativeObject",
- __native: ret
- };
+ nativeToRubyObject: function(v) {
+ if(typeof(v) == "number") {
+ return v;
+ }
+ if(typeof(v) == "string") {
+ return this.createRubyString(v);
+ }
+ if(typeof(v) == "object" && v instanceof Array) {
+ return this.createRubyArray(v);
+ }
+ return {
+ __className: "NativeObject",
+ __native: v
+ };
+ },
+
+ /**
+ * Convert array of native object to array of ruby object
+ * @param {Array} ary Array of native object
+ */
+ nativeAryToRubyObjectAry: function(ary) {
+ var convAry = new Array(ary.length);
+ for(var i=0; i<ary.length; i++) {
+ convAry[i] = this.nativeToRubyObject(ary[i]);
}
+ return convAry;
},
/**
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
textField = $native.TextField.new
textField.autoSize = $native.TextFieldAutoSize.LEFT
-textField.text = "Memory: " + $native.System.totalMemory.to_s + " bytes"
+textField.text = "Memory: " + $native.System.totalMemory.to_s + " bytes\n"
$native._root.addChild(textField)
g = $native._root.graphics
@@ -12,5 +12,5 @@
g.drawCircle 200, 200, 100
g.endFill
-callback = Proc.new { textField.text += "clicked" }
+callback = Proc.new {|evt| textField.text += "type: " + evt.type + "\n" }
textField.addEventListener "click", callback
@@ -136,7 +136,7 @@
],
[
"putstring",
- " bytes"
+ " bytes\n"
],
[
"send",
@@ -361,32 +361,42 @@
1,
1,
{
- "arg_size": 0,
- "local_size": 0,
- "stack_max": 3
+ "arg_size": 1,
+ "local_size": 1,
+ "stack_max": 4
},
"block in <main>",
"asEnv\\asEnv.rb",
"block",
[
+ "evt"
+ ],
+ [
+ 1,
+ [
+ ],
+ 0,
+ 0,
+ -1,
+ -1,
+ 3
],
- 0,
[
[
"redo",
null,
"label_0",
- "label_24",
+ "label_47",
"label_0",
0
],
[
"next",
null,
"label_0",
- "label_24",
- "label_24",
+ "label_47",
+ "label_47",
0
]
],
@@ -411,7 +421,40 @@
],
[
"putstring",
- "clicked"
+ "type: "
+ ],
+ [
+ "getdynamic",
+ 1,
+ 0
+ ],
+ [
+ "send",
+ "type",
+ 0,
+ null,
+ 0,
+ null
+ ],
+ [
+ "send",
+ "+",
+ 1,
+ null,
+ 0,
+ null
+ ],
+ [
+ "putstring",
+ "\n"
+ ],
+ [
+ "send",
+ "+",
+ 1,
+ null,
+ 0,
+ null
],
[
"send",
@@ -429,7 +472,7 @@
0,
null
],
- "label_24",
+ "label_47",
[
"leave"
]

0 comments on commit 821c489

Please sign in to comment.