Class: Rednode::Process

Inherits:
EventEmitter show all
Includes:
Constants, Namespace
Defined in:
lib/rednode/process.rb

Defined Under Namespace

Classes: Env, Timer

Constant Summary collapse

EventEmitter =
self.superclass

Instance Attribute Summary collapse

Attributes inherited from EventEmitter

#_events

Instance Method Summary collapse

Methods included from Namespace

#[]

Methods included from Constants

defc

Methods inherited from EventEmitter

#emit

Constructor Details

#initialize(node) ⇒ Process

Returns a new instance of Process.



8
9
10
11
12
13
14
15
# File 'lib/rednode/process.rb', line 8

def initialize(node)
  @node = node
  @engine = node.engine
  @global = @engine.scope
  @bindings = {}
  @env = Env.new
  @scheduler = Rednode::Scheduler.new
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/rednode/process.rb', line 6

def env
  @env
end

#globalObject (readonly)

Returns the value of attribute global.



6
7
8
# File 'lib/rednode/process.rb', line 6

def global
  @global
end

#schedulerObject (readonly)

Returns the value of attribute scheduler.



6
7
8
# File 'lib/rednode/process.rb', line 6

def scheduler
  @scheduler
end

Instance Method Details

#_byteLength(str, encoding = 'utf8') ⇒ Object



50
51
52
53
# File 'lib/rednode/process.rb', line 50

def _byteLength(str, encoding = 'utf8')
  chars = encoding == 'utf8' ? str.unpack('C*') : str.unpack('U*')
  chars.length
end

#_needTickCallback(*args) ⇒ Object



72
73
74
75
76
# File 'lib/rednode/process.rb', line 72

def _needTickCallback(*args)
  @scheduler.next_tick do
    @node.engine.eval("process._tickCallback()")
  end
end

#argvObject



38
39
40
# File 'lib/rednode/process.rb', line 38

def argv
  ['rednode', @node.main]
end

#binding(id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rednode/process.rb', line 17

def binding(id)
  if @bindings[id]
    @bindings[id]
  elsif Rednode::Bindings::const_defined?(pascalize(id))
    @bindings[id] = Rednode::Bindings::const_get(pascalize(id)).new
  elsif id == "natives"
    exports = @engine['Object'].new
    for native in Dir["#{NODE_HOME}/lib/*.js"]
      File.basename(native) =~ /^(.*)\.js$/
      exports[$1] = File.read(native)
    end
    @bindings[id] = exports
  else
    raise "no such module: #{id}"
  end
end

#chdir(dirname) ⇒ Object



46
47
48
# File 'lib/rednode/process.rb', line 46

def chdir(dirname)
  Dir.chdir(dirname)
end

#compile(source, filename) ⇒ Object



34
35
36
# File 'lib/rednode/process.rb', line 34

def compile(source, filename)
  @engine.eval(source, filename)
end

#cwd(*args) ⇒ Object



42
43
44
# File 'lib/rednode/process.rb', line 42

def cwd(*args)
  Dir.pwd
end

#dlopen(filename, exports) ⇒ Object



64
65
66
# File 'lib/rednode/process.rb', line 64

def dlopen(filename, exports)
  raise "Rednode currently can't read native (.node) modules. Failed to load: #{filename}"
end

#loop(*args) ⇒ Object



60
61
62
# File 'lib/rednode/process.rb', line 60

def loop(*args)
  @scheduler.start_loop
end

#TimerObject



105
106
107
# File 'lib/rednode/process.rb', line 105

def Timer
  @timer ||= lambda { Process::Timer.new(self) }
end

#umask(mask = nil) ⇒ Object



68
69
70
# File 'lib/rednode/process.rb', line 68

def umask(mask = nil)
  mask ? File.umask(mask) : File.umask
end

#versionObject

TODO: find a good place to read this.



56
57
58
# File 'lib/rednode/process.rb', line 56

def version
  "0.2.0"
end