Skip to content
Browse files

compiles and tests run

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

0 comments on commit 43008e5

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