Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

compiles and tests run

  • Loading branch information...
commit 43008e50a9255955ced0be73186d51aff1370537 1 parent 20492e0
Aaron Patterson authored
4 Rakefile
@@ -2,6 +2,8 @@
2 2
3 3 require 'rubygems'
4 4 require 'hoe'
  5 +gem 'rake-compiler', '>= 0.4.1'
  6 +require "rake/extensiontask"
5 7
6 8 HOE = Hoe.spec 'phuby' do
7 9 developer('Aaron Patterson', 'aaronp@rubyforge.org')
@@ -12,7 +14,7 @@ HOE = Hoe.spec 'phuby' do
12 14 self.spec_extras = { :extensions => ["ext/phuby/extconf.rb"] }
13 15 end
14 16
15   -RET = Rake::ExtensionTask.new("nokogiri", HOE.spec) do |ext|
  17 +RET = Rake::ExtensionTask.new("phuby", HOE.spec) do |ext|
16 18 ext.lib_dir = File.join('lib', 'phuby')
17 19 end
18 20
4 ext/phuby/extconf.rb
@@ -6,8 +6,10 @@
6 6
7 7 php_inc, php_lib = dir_config('php5', '/usr/local/include', '/usr/local/lib')
8 8
  9 +$INCFLAGS = "-I#{File.join(php_inc, 'php')}".quote + " #{$INCFLAGS}"
  10 +
9 11 %w{ Zend TSRM main }.each do |dir|
10   - $INCFLAGS = "-I#{File.join(php_inc, dir)}".quote + " #{$INCFLAGS}"
  12 + $INCFLAGS = "-I#{File.join(php_inc, 'php', dir)}".quote + " #{$INCFLAGS}"
11 13 end
12 14
13 15 unless find_library('php5', 'php_embed_init', php_lib)
41 ext/phuby/phuby.c
... ... @@ -0,0 +1,41 @@
  1 +#include <phuby.h>
  2 +
  3 +
  4 +VALUE mPhuby;
  5 +VALUE cPhubyRuntime;
  6 +
  7 +static VALUE start(VALUE self)
  8 +{
  9 + /* FIXME:
  10 + * I got these from the book. I don't know wtf they're for yet. */
  11 + int argc = 1;
  12 + char *argv[2] = { "embed4", NULL };
  13 +
  14 + php_embed_init(argc, argv);
  15 +
  16 + return Qnil;
  17 +}
  18 +
  19 +static VALUE native_eval(VALUE self, VALUE string, VALUE filename)
  20 +{
  21 + zend_first_try {
  22 + zend_eval_string(
  23 + StringValuePtr(string),
  24 + NULL,
  25 + StringValuePtr(filename)
  26 + );
  27 + } zend_end_try();
  28 +
  29 + return Qnil;
  30 +}
  31 +
  32 +void Init_phuby()
  33 +{
  34 + mPhuby = rb_define_module("Phuby");
  35 +
  36 + /* FIXME: This belongs in it's own .c file */
  37 + cPhubyRuntime = rb_define_class_under(mPhuby, "Runtime", rb_cObject);
  38 +
  39 + rb_define_method(cPhubyRuntime, "start", start, 0);
  40 + rb_define_private_method(cPhubyRuntime, "native_eval", native_eval, 2);
  41 +}
8 ext/phuby/phuby.h
... ... @@ -0,0 +1,8 @@
  1 +#ifndef PHUBY
  2 +#define PHUBY
  3 +
  4 +#include <stdlib.h>
  5 +#include <ruby.h>
  6 +#include <sapi/embed/php_embed.h>
  7 +
  8 +#endif
5 lib/phuby.rb
... ... @@ -1,3 +1,6 @@
1   -class Phuby
  1 +require 'phuby/phuby'
  2 +require 'phuby/runtime'
  3 +
  4 +module Phuby
2 5 VERSION = '1.0.0'
3 6 end
7 lib/phuby/runtime.rb
... ... @@ -0,0 +1,7 @@
  1 +module Phuby
  2 + class Runtime
  3 + def eval string, filename = __FILE__
  4 + native_eval string, filename
  5 + end
  6 + end
  7 +end
7 test/test_phuby.rb
@@ -2,7 +2,10 @@
2 2 require "phuby"
3 3
4 4 class TestPhuby < Test::Unit::TestCase
5   - def test_sanity
6   - flunk "write tests or I will kneecap you"
  5 + def test_runtime
  6 + rt = Phuby::Runtime.new
  7 + rt.start
  8 + rt.eval("$hi = 'Hello World';")
  9 + rt.eval("echo $hi;")
7 10 end
8 11 end

0 comments on commit 43008e5

Please sign in to comment.
Something went wrong with that request. Please try again.