Created
September 13, 2012 16:11
-
-
Save tk3/3715429 to your computer and use it in GitHub Desktop.
F# meets mruby
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
#include "Mrb.h" | |
#include "mruby.h" | |
#include "mruby/proc.h" | |
#include "mruby/array.h" | |
#include "mruby/string.h" | |
#include "mruby/compile.h" | |
#include "mruby/dump.h" | |
using namespace Mrb; | |
State::State() | |
{ | |
mrb = mrb_open(); | |
} | |
State::~State() | |
{ | |
this->!State(); | |
} | |
State::!State() | |
{ | |
if (mrb != NULL) { | |
mrb_close(mrb); | |
} | |
} | |
void State::ExecString(String^ s) | |
{ | |
IntPtr ptr; | |
mrb_value ret; | |
ptr = Marshal::StringToHGlobalAnsi(s); | |
ret = mrb_load_string(mrb, (char *)ptr.ToPointer()); | |
Marshal::FreeHGlobal(ptr); | |
ret = mrb_funcall(mrb, ret, "inspect", 0); | |
fwrite(RSTRING_PTR(ret), RSTRING_LEN(ret), 1, stdout); | |
// putc('\n', stdout); | |
} |
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
#pragma once | |
#include "mruby.h" | |
using namespace System; | |
using namespace System::Runtime::InteropServices; | |
namespace Mrb | |
{ | |
public ref class State | |
{ | |
private: | |
mrb_state *mrb; | |
public: | |
State(); | |
~State(); | |
!State(); | |
void ExecString(String ^s); | |
}; | |
}; |
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
#light | |
open System | |
open System.IO | |
open Mrb | |
[<EntryPoint>] | |
let main (args : string[]) = | |
let reader = new StreamReader(args.[0]) | |
let mrb_src = reader.ReadToEnd() | |
reader.Close() | |
let mrb = new Mrb.State() | |
mrb.ExecString(mrb_src) | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment