Created
June 21, 2018 07:11
-
-
Save pandax381/97037385b313bf8ced06f8540d239efc to your computer and use it in GitHub Desktop.
mruby on arduino-esp32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include "sdkconfig.h" | |
#include "mruby.h" | |
#include "mruby/irep.h" | |
#include "mruby/compile.h" | |
#include "mruby/error.h" | |
#include "mruby/string.h" | |
const uint8_t mrbcode[] = { | |
0x45,0x54,0x49,0x52,0x30,0x30,0x30,0x34,0x4f,0x5a,0x00,0x00,0x01,0x47,0x4d,0x41, | |
0x54,0x5a,0x30,0x30,0x30,0x30,0x49,0x52,0x45,0x50,0x00,0x00,0x01,0x0b,0x30,0x30, | |
0x30,0x30,0x00,0x00,0x01,0x03,0x00,0x03,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x1a, | |
0x06,0x00,0x80,0x01,0x3d,0x00,0x00,0x02,0xa0,0x00,0x80,0x01,0x11,0x01,0x80,0x01, | |
0x93,0x00,0x80,0x01,0x20,0xc0,0x80,0x01,0x01,0xc0,0x80,0x00,0x06,0x00,0x80,0x01, | |
0xbd,0x00,0x00,0x02,0x01,0x40,0x80,0x02,0x3e,0x40,0x01,0x02,0xa0,0x00,0x80,0x01, | |
0x11,0x01,0x80,0x01,0x93,0x00,0x80,0x01,0x20,0x00,0x81,0x01,0x83,0xf3,0x41,0x02, | |
0xb1,0x40,0x81,0x01,0x01,0xc0,0x00,0x01,0x06,0x00,0x80,0x01,0xbd,0x01,0x00,0x02, | |
0x01,0x80,0x80,0x02,0x3e,0x40,0x01,0x02,0x3d,0x02,0x80,0x02,0x3e,0x40,0x01,0x02, | |
0xa0,0x00,0x80,0x01,0x4a,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x1a,0x6d, | |
0x72,0x75,0x62,0x79,0x20,0x69,0x73,0x20,0x72,0x75,0x6e,0x6e,0x69,0x6e,0x67,0x20, | |
0x6f,0x6e,0x20,0x45,0x53,0x50,0x33,0x32,0x21,0x00,0x00,0x0d,0x53,0x44,0x4b,0x20, | |
0x56,0x65,0x72,0x73,0x69,0x6f,0x6e,0x3a,0x20,0x00,0x00,0x00,0x00,0x00,0x0d,0x4d, | |
0x65,0x6d,0x6f,0x72,0x79,0x20,0x66,0x72,0x65,0x65,0x3a,0x20,0x00,0x00,0x01,0x4b, | |
0x00,0x00,0x00,0x06,0x00,0x04,0x70,0x75,0x74,0x73,0x00,0x00,0x06,0x53,0x79,0x73, | |
0x74,0x65,0x6d,0x00,0x00,0x05,0x45,0x53,0x50,0x33,0x32,0x00,0x00,0x0b,0x73,0x64, | |
0x6b,0x5f,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x00,0x00,0x10,0x61,0x76,0x61,0x69, | |
0x6c,0x61,0x62,0x6c,0x65,0x5f,0x6d,0x65,0x6d,0x6f,0x72,0x79,0x00,0x00,0x01,0x2f, | |
0x00,0x4c,0x56,0x41,0x52,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x02,0x00,0x03,0x76, | |
0x65,0x72,0x00,0x03,0x6d,0x65,0x6d,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x02,0x45, | |
0x4e,0x44,0x00,0x00,0x00,0x00,0x08, | |
}; | |
void setup() { | |
// put your setup code here, to run once: | |
} | |
void loop() { | |
mrb_state *mrb = mrb_open(); | |
mrbc_context *context = mrbc_context_new(mrb); | |
int ai = mrb_gc_arena_save(mrb); | |
ESP_LOGI(TAG, "%s", "Loading binary..."); | |
mrb_load_irep_cxt(mrb, mrbcode, context); | |
if (mrb->exc) { | |
ESP_LOGE(TAG, "Exception occurred: %s", mrb_str_to_cstr(mrb, mrb_inspect(mrb, mrb_obj_value(mrb->exc)))); | |
mrb->exc = 0; | |
} else { | |
ESP_LOGI(TAG, "%s", "Success"); | |
} | |
mrb_gc_arena_restore(mrb, ai); | |
mrbc_context_free(mrb, context); | |
mrb_close(mrb); | |
// This task should never end, even if the | |
// script ends. | |
while (1) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment