unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Panel1: TPanel;
    Button1: TButton;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

uses Rubies, Pythia, uAppInit;

{$R *.DFM}

procedure Stdout(S: string);
begin
  with Form1.Memo1 do
  begin
    with Lines do Text := Text + S;
    SelStart := Length(Text);
    SelLength := 0;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  PhiAppInit;
  PhiSetStdoutProc(Stdout);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  argc: Integer;
  argv: Pointer;
  args: array of PChar;
begin
  rb_ary_clear(ap_argv);
  argc := 1;
  SetLength(args, argc);
  argv := args;
  args[0] := PChar(Edit1.Text);
  ruby_set_argv(argc, argv);
  PhiLoadProtect('fact.rb', nil);
end;

end.
