typos and a test-box

This commit is contained in:
Denis Knauf 2010-03-21 00:24:24 +01:00
parent d27b1b3852
commit 054be00221
4 changed files with 51 additions and 22 deletions

View file

@ -1 +1 @@
0.0.0 0.0.1

27
bin/box.rb Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/ruby
begin
require 'sbdb'
rescue LoadError
$stderr.puts "Install sbdb: gem install sbdb"
exit 1
end
require 'safebox'
_ = nil
Dir.mkdir 'logs' rescue Errno::EEXIST
SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs|
db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE]
db = Safebox::Persistent.new db, db.cursor
$stdout.print "(0)$ "
STDIN.each_with_index do |line, i|
ret = Safebox.run line, Safebox::Box, db, _
if :value == ret.first
_ = ret.last
$stdout.puts "=> #{ret.last.inspect}"
else
$stdout.puts ret.last.inspect, ret.last.backtrace.map( &" %s".method( :%))
end
$stdout.print "(#{i+1})$ "
end
end

View file

@ -1,4 +1,4 @@
require 'safebox/sanfeox' require 'safebox/safebox'
class Safebox::Box class Safebox::Box
attr_reader :_, :db attr_reader :_, :db

View file

@ -1,25 +1,27 @@
module Safebox module Safebox
def self.run *paras, &exe class <<self
exe = paras.shift unless exe def run *paras, &exe
box = paras.shift || Class exe = paras.shift unless exe
Thread.new do box = paras.shift || Class
$SAFE = 4 Thread.new do
this = box.new *paras $SAFE = 4
begin this = box.new *paras
[:value, this.instance_eval( exe, "Safebox")] begin
rescue Object [:value, this.instance_eval( exe, "Safebox")]
[:exception, $!] rescue Object
end [:exception, $!]
end.value end
end end.value
def self.create_class *paras, &exe
exe = paras.shift unless exe
run Class, *paras do
eval exe
self
end end
def create_class *paras, &exe
exe = paras.shift unless exe
self.run Class, *paras do
eval exe
self
end
end
alias new_class create_class
end end
alias new_class create_class
end end