karas 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +17 -0
- data/ext/karas/extconf.rb +29 -0
- data/ext/karas/karas.c +47 -0
- data/karas.gemspec +20 -0
- data/lib/karas/version.rb +3 -0
- data/test/karas_test.rb +15 -0
- data/test/test_helper.rb +5 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Josef Šimánek
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Karas
|
2
|
+
|
3
|
+
Dummy embedded PHP interpreter in Ruby
|
4
|
+
|
5
|
+
## Motivation
|
6
|
+
|
7
|
+
Learn new things
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'karas'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install karas
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Karas.evaluate('echo "Hello from PHP Karas";') #=> 'Hello from PHP Karas';
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/extensiontask'
|
6
|
+
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
Rake::ExtensionTask.new('karas')
|
9
|
+
|
10
|
+
desc "Build eventmachine, then run tests."
|
11
|
+
task :default => [:clean,:compile, :test]
|
12
|
+
|
13
|
+
Rake::TestTask.new(:test) do |t|
|
14
|
+
t.libs << 'test'
|
15
|
+
t.pattern = 'test/**/*_test.rb'
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Loads mkmf which is used to make makefiles for Ruby extensions
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
$CFLAGS = "-Wall"
|
5
|
+
|
6
|
+
# Give it a name
|
7
|
+
extension_name = 'karas'
|
8
|
+
|
9
|
+
# The destination
|
10
|
+
dir_config(extension_name)
|
11
|
+
|
12
|
+
config = "php-config"
|
13
|
+
|
14
|
+
prefix = `#{config} --prefix`.chomp
|
15
|
+
|
16
|
+
php_inc, php_lib = dir_config("php5", "#{prefix}/include", "#{prefix}/lib")
|
17
|
+
|
18
|
+
$INCFLAGS = "-I#{File.join(php_inc, "php").quote} #{$INCFLAGS}"
|
19
|
+
|
20
|
+
%w{ Zend TSRM main }.each do |dir|
|
21
|
+
$INCFLAGS = "-I#{File.join(php_inc, "php", dir).quote} #{$INCFLAGS}"
|
22
|
+
end
|
23
|
+
|
24
|
+
unless find_library("php5", "php_embed_init", php_lib)
|
25
|
+
abort "php is missing!"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Do the work
|
29
|
+
create_makefile(extension_name)
|
data/ext/karas/karas.c
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <sapi/embed/php_embed.h>
|
3
|
+
|
4
|
+
VALUE Karas = Qnil;
|
5
|
+
char * buffer = NULL;
|
6
|
+
int errors = 0;
|
7
|
+
|
8
|
+
void Init_karas();
|
9
|
+
VALUE method_eval(VALUE self, VALUE php_code);
|
10
|
+
|
11
|
+
void Init_karas() {
|
12
|
+
Karas = rb_define_module("Karas");
|
13
|
+
rb_define_singleton_method(Karas, "evaluate", method_eval, 1);
|
14
|
+
}
|
15
|
+
|
16
|
+
static int karas_ub_write(const char *str, unsigned int strlen) {
|
17
|
+
buffer = malloc(strlen + 1);
|
18
|
+
strcpy(buffer, str);
|
19
|
+
return strlen;
|
20
|
+
}
|
21
|
+
|
22
|
+
static void karas_log_message(char * message) {
|
23
|
+
errors++;
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE method_eval(VALUE self, VALUE php_code) {
|
27
|
+
char *php_c_code;
|
28
|
+
int argc = 1;
|
29
|
+
char *argv[2] = { "Karas", NULL };
|
30
|
+
buffer = NULL;
|
31
|
+
errors = 0;
|
32
|
+
|
33
|
+
php_c_code = StringValuePtr(php_code);
|
34
|
+
|
35
|
+
php_embed_module.ub_write = karas_ub_write;
|
36
|
+
php_embed_module.log_message = karas_log_message;
|
37
|
+
|
38
|
+
PHP_EMBED_START_BLOCK (argc, argv);
|
39
|
+
|
40
|
+
zend_eval_string(php_c_code, NULL, "Karas");
|
41
|
+
|
42
|
+
PHP_EMBED_END_BLOCK ();
|
43
|
+
|
44
|
+
if(errors > 0) return Qfalse;
|
45
|
+
if(buffer != NULL) return rb_str_new2(buffer);
|
46
|
+
return Qtrue;
|
47
|
+
}
|
data/karas.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/karas/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Josef Šimánek"]
|
6
|
+
gem.email = ["retro@ballgag.cz"]
|
7
|
+
gem.description = %q{PHP in Ruby}
|
8
|
+
gem.summary = %q{Just a stupid relax project}
|
9
|
+
gem.homepage = ""
|
10
|
+
gem.extensions = ["ext/karas/extconf.rb"]
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "karas"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Karas::VERSION
|
18
|
+
|
19
|
+
gem.add_development_dependency "rake-compiler"
|
20
|
+
end
|
data/test/karas_test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestKaras < MiniTest::Unit::TestCase
|
4
|
+
def test_karas_valid_echo
|
5
|
+
assert_equal 'ryba', Karas.evaluate("echo 'ryba';")
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_karas_valid_code
|
9
|
+
assert_equal true, Karas.evaluate("$a = 1;")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_karas_invalid_code
|
13
|
+
assert_equal false, Karas.evaluate("echo ryba'")
|
14
|
+
end
|
15
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: karas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josef Šimánek
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake-compiler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: PHP in Ruby
|
31
|
+
email:
|
32
|
+
- retro@ballgag.cz
|
33
|
+
executables: []
|
34
|
+
extensions:
|
35
|
+
- ext/karas/extconf.rb
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- ext/karas/extconf.rb
|
44
|
+
- ext/karas/karas.c
|
45
|
+
- karas.gemspec
|
46
|
+
- lib/karas/version.rb
|
47
|
+
- test/karas_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
homepage: ''
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.22
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Just a stupid relax project
|
73
|
+
test_files:
|
74
|
+
- test/karas_test.rb
|
75
|
+
- test/test_helper.rb
|