Giter Club home page Giter Club logo

mrubyc_with_platformio's Introduction

mrubyc_with_platformio

mruby/cをplatformioでビルドする

依存

  • PlatformIO 4.x

    • Python 3.x
  • mruby/c 1.2

    • mruby 2.0.1
    • ruby 2.x

使い方

初期設定

  1. 作業用フォルダを作成、移動
mkdir your_work_space
cd .\your_work_space
  1. 作業フォルダ内でPlatformIOで開発環境の設定
cd ..
pio init --ide your_ide_id --board your_board_ide
  1. libフォルダ内でmrubycのリポジトリをクローン
cd ./lib
git clone https://github.com/mrubyc/mrubyc.git
  1. 作業用フォルダ内でこのリポジトリをクローン
cd ..
git clone https://github.com/yusuke-ota/mrubyc_with_platformio.git
  1. mrubyc_with_platformio/srcをsrcディレクトリに上書き
mv -r ./mrubyc_with_platformio/src ./src
rm -r ./mrubyc_with_platformio
  1. lib/mrubyc/srcにあるhal_*ディレクトリの内、使用するボードに対応するものをhalにリネーム
REN ./lib/mrubyc/src/hal_you_use ./lib/mrubyc/src/hal
rm -r ./lib/mrubyc/src/hal_*
  1. 作業フォルダ内でPlatformIOで開発環境の初期化

libディレクトリをいじった後は毎回行う

pio init --ide your_ide_id --board your_board_ide

作業手順

  1. src内のmain.cppにrubyで使用したいメソッドを登録
// sample method
// When you write your method, write like this.
//
void c_sample_method(VM *VM, mrbc_value *v, int arg){
}
// 上の空関数を参考に、使用したい関数を実装

static void mrbc_define_methods(){
    mrbc_define_method(nullptr, mrbc_class_object, "sample_method", c_sample_method);
    // 上の関数を参考に、rubyで呼び出したいメソッドを登録
}
  1. srcフォルダの中でRubyファイルを作成、編集

  2. Rubyファイルをmrubyコンパイラでコンパイル

mrbc.exe -E -B your_file_name your_file_name.rb
  1. コンパイル後の*.cコードをmain.cppから呼び出し
#include "Arduino.h"
#include "mrubyc.h"

// 後ほどmrubyのコンパイラでコンパイルした.rbファイルの処理が格納される配列です。
extern const uint8_t your_file_name[];
  1. PlatformIOでビルド、アップロード

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.