Skip to content

Instantly share code, notes, and snippets.

@tk3
Created September 13, 2012 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk3/3715429 to your computer and use it in GitHub Desktop.
Save tk3/3715429 to your computer and use it in GitHub Desktop.
F# meets mruby
#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);
}
#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);
};
};
#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