Skip to content

Dataの命令ブロックをRubyに変換できるようにしました #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

t-kazu
Copy link
Collaborator

@t-kazu t-kazu commented Oct 20, 2018

命令ブロック Ruby
screenshot from 2018-10-20 15-33-08 screenshot from 2018-10-20 15-33-14

現状だと、Arrayを定義する文が書けないため違和感のあるコードになっていまいます。
どこかで、リスト = Array.new みたいなものがどこかで欲しいなとは思いました

@takaokouji
Copy link

スクラッチ互換にするためには、ローカル変数は、スプライトのインスタンス変数として定義しないといけないのですよね。

つまり、
作った変数 = 0
は、
@作った変数 = 0
としてほしいです。

グローバル変数は、
$作った変数 = 0
だね。

@takaokouji
Copy link

リストの一番目が間違っていそう。
「リ」になってるね。
リスト[0]
だね。

@takaokouji
Copy link

あと、CIが失敗しているので、eslint をパスしてないかも。

@takaokouji
Copy link

リストもグローバルではなくて、ローカル変数なので、
@リスト = []
だね。

いや、正しくは、
sprite(“スプライト1”).make_list(“リスト”)
かな。

@takaokouji
Copy link

リストや変数の定義は、
index.js
の方で定義します。
別チケットでやりましょう。

具体的には、
全ての変数、リストに対して、
Blockly.Ruby.definition_[list_#{リストの名前}] = sprite(...).make_list(...)
を設定します。

Copy link
Collaborator Author

@t-kazu t-kazu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スクラッチ互換にするためには、ローカル変数は、スプライトのインスタンス変数として定義しないといけないのですよね。

つまり、
作った変数 = 0
は、
@作った変数 = 0
としてほしいです。

グローバル変数は、
$作った変数 = 0
だね。

これに関しては、対処方法が見つかっていないため時間が掛かりそうです。

@t-kazu t-kazu force-pushed the feature/rubygenerator-for-data-blocks branch from e404a6f to f9bee24 Compare October 20, 2018 07:13
@t-kazu t-kazu force-pushed the feature/rubygenerator-for-data-blocks branch from f9bee24 to bf1a04b Compare October 20, 2018 07:15
@takaokouji
Copy link

this.editingTarget.lookupVariableByNameAndType(変数名) で変数、 this.editingTarget.lookupVariableByNameAndType(リスト名, 'list') でリストが取れました。

ここには、ローカルかグローバルかの情報はなさそうですね。

@takaokouji
Copy link

takaokouji commented Oct 20, 2018

this.editingTarget.lookupVariableByNameAndType(変数名, '', false) で値が取れたらローカル変数、とれなければグローバル変数でした。

これはあまりにもトリッキーなので、
Blockly.Ruby.variableName(name)
という関数を用意して、
その関数の中で、ローカル変数ならば
@変数名
を返し、
グローバル変数ならば
$グローバル変数名
を返すようにしましょうかね。

ということで、以下の Blockly.Ruby.variableName(name) を index.js に定義して、それを呼び出すことにしてもらってもいいでしょうか?

    Blockly.Ruby.variableName = function (name, type = '') {
        if (this.editingTarget.lookupVariableByNameAndType(name, type, false)) {
            return `@#{name}`;
        }
        return `$#{name}`;
    };

    Blockly.Ruby.listName = function (name) {
        return this.variableName(name, 'list');
    };

@t-kazu
Copy link
Collaborator Author

t-kazu commented Oct 20, 2018

調べて頂き誠にありがとうございました。
承知しました。Blockly.Ruby.variableName(name) を index.js に定義して、実装します

@takaokouji takaokouji merged commit 7746135 into smalruby:develop Oct 21, 2018
@t-kazu t-kazu deleted the feature/rubygenerator-for-data-blocks branch October 22, 2018 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants