unit Unit2;

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, Pseudo, 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
  script, params: TStringList;
begin
  rb_ary_clear(ap_argv);
  script := nil;
  params := nil;
  try
    script := TStringList.Create;
    params := TStringList.Create;
    script.LoadFromFile('fact.rb');
    params.Add(Edit1.Text);
    RubyEvalStrings(script, params, Memo1.Lines);
  finally
    params.Free;
    script.Free;
  end;
end;

end.
