Skip to content

Commit

Permalink
#require
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Jan 29, 2012
1 parent 5e90aa7 commit af0f943
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kernel/test_case.nsc
@@ -1,5 +1,5 @@
!RBIX
2199918003027222139
14826142347510856616
0
M
1
Expand Down
2 changes: 1 addition & 1 deletion kernel/traits.nsc
@@ -1,5 +1,5 @@
!RBIX
2199918003027222139
14826142347510856616
0
M
1
Expand Down
21 changes: 18 additions & 3 deletions lib/noscript/runtime.rb
Expand Up @@ -90,8 +90,8 @@ def method_missing(m, *args)
end

module Kernel
def noscript_require(file)
here = File.dirname(caller.first.split(":").first)
def noscript_require(file, backtrace=caller)
here = File.dirname(backtrace.first.split(":").first)
old_paths = Noscript::CodeLoader.load_paths
Noscript::CodeLoader.load_paths.unshift(here)
Noscript::CodeLoader.run(file)
Expand Down Expand Up @@ -175,9 +175,24 @@ def noscript_send(name, *args)
send *args
end

noscript_def("require") do |file|
backtrace = [caller.detect {|line| line =~ /eval_noscript/}]
noscript_require(file, backtrace)
end

noscript_def("ruby require") do |file|
require file
end

noscript_def("ruby require relative") do |file|
backtrace = [caller.detect {|line| line =~ /eval_noscript/}]
here = File.dirname(backtrace.first.split(":").first)
require File.expand_path(File.join(here, file))
end

noscript_alias [:==, :"!="]
noscript_alias [:include, :extend, :def]
noscript_def("@!") { !self }
noscript_def("!") { !self }

noscript_alias :nil?
noscript_alias :inspect
Expand Down

0 comments on commit af0f943

Please sign in to comment.