Skip to content

Commit

Permalink
Keep all corelib globals in relevant files
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 25, 2013
1 parent 1174f5b commit 302ded2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 44 deletions.
3 changes: 3 additions & 0 deletions corelib/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ def to_n

TrueClass = Boolean
FalseClass = Boolean

TRUE = true
FALSE = false
30 changes: 30 additions & 0 deletions corelib/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,33 @@ def readpartial(integer, outbuf = nil)
end
end
end

STDERR = $stderr = IO.new
STDIN = $stdin = IO.new
STDOUT = $stdout = IO.new

def $stdout.puts(*strs)
%x{
for (var i = 0; i < strs.length; i++) {
if(strs[i] instanceof Array) {
#{ puts(*`strs[i]`) }
} else {
console.log(#{`strs[i]`.to_s});
}
}
}
nil
end

def $stderr.puts(*strs)
%x{
for (var i = 0; i < strs.length; i++) {
if(strs[i] instanceof Array) {
#{ puts(*`strs[i]`) }
} else {
console.warn(#{`strs[i]`.to_s});
}
}
}
nil
end
7 changes: 7 additions & 0 deletions corelib/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def self.to_s
'main'
end

def self.include(mod)
Object.include mod
end
3 changes: 3 additions & 0 deletions corelib/native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,6 @@ def nil?
false
end
end

# native global
$$ = $global = Native(`Opal.global`)
2 changes: 2 additions & 0 deletions corelib/nil_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ def object_id
end
alias hash object_id
end

NIL = nil
45 changes: 1 addition & 44 deletions corelib/opal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require 'struct'
require 'native'
require 'io'
require 'main'

# regexp matches
$& = $~ = $` = $' = nil
Expand All @@ -33,56 +34,12 @@
$/ = "\n"
$, = " "

# native global
$$ = $global = Native(`Opal.global`)

ARGV = []
ARGF = Object.new
ENV = {}
TRUE = true
FALSE = false
NIL = nil

STDERR = $stderr = IO.new
STDIN = $stdin = IO.new
STDOUT = $stdout = IO.new

def $stdout.puts(*strs)
%x{
for (var i = 0; i < strs.length; i++) {
if(strs[i] instanceof Array) {
#{ puts(*`strs[i]`) }
} else {
console.log(#{`strs[i]`.to_s});
}
}
}
nil
end

def $stderr.puts(*strs)
%x{
for (var i = 0; i < strs.length; i++) {
if(strs[i] instanceof Array) {
#{ puts(*`strs[i]`) }
} else {
console.warn(#{`strs[i]`.to_s});
}
}
}
nil
end

RUBY_PLATFORM = 'opal'
RUBY_ENGINE = 'opal'
RUBY_VERSION = '1.9.3'
RUBY_ENGINE_VERSION = '0.4.4'
RUBY_RELEASE_DATE = '2013-08-13'

def self.to_s
'main'
end

def self.include(mod)
Object.include mod
end

0 comments on commit 302ded2

Please sign in to comment.