Skip to content

Instantly share code, notes, and snippets.

@tosik
Created March 18, 2014 03:15
Show Gist options
  • Select an option

  • Save tosik/9612909 to your computer and use it in GitHub Desktop.

Select an option

Save tosik/9612909 to your computer and use it in GitHub Desktop.
mruby on iOS 導入部分メモ
mrb = mrb_open();
NSString * bcfile = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"context.mrb"];
NSFileHandle * fileHandle = [NSFileHandle fileHandleForReadingAtPath:bcfile];
NSData * data = [fileHandle readDataToEndOfFile];
uint8_t * bytes = (uint8_t *)malloc([data length]);
memcpy(bytes, [data bytes], [data length]);
[fileHandle closeFile];
mrb_load_irep(mrb, bytes);
@tosik
Copy link
Author

tosik commented Mar 18, 2014

mruby on iOS な環境で context.rb を読み込んで実行するところ。
読み込んだファイルのバイトコードを malloc した場所に memcpy してるのは、
これをしないと mrb_state が読み込むバイトコードが GC されて消えるから。

iOS の GC 周りよくわかってないので、もっと良い方法があるかも。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment