Created
March 18, 2014 03:15
-
-
Save tosik/9612909 to your computer and use it in GitHub Desktop.
mruby on iOS 導入部分メモ
This file contains hidden or 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
| 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); | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mruby on iOS な環境で context.rb を読み込んで実行するところ。
読み込んだファイルのバイトコードを malloc した場所に memcpy してるのは、
これをしないと mrb_state が読み込むバイトコードが GC されて消えるから。
iOS の GC 周りよくわかってないので、もっと良い方法があるかも。