Module: Neri

Defined in:
lib/neri/ayame.rb,
lib/neri/dxruby.rb,
lib/neri/runtime.rb,
lib/neri/version.rb

Defined Under Namespace

Modules: Ayame, DXRubyImage, DXRubySound

Constant Summary collapse

BLOCK_LENGTH =
32
VERSION =
-"1.1.0"

Class Method Summary collapse

Class Method Details

.datafile=(datafile) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/neri/runtime.rb', line 34

def datafile=(datafile)
  @datafile = datafile.encode(Encoding::UTF_8)
  files_length = File.binread(@datafile, BLOCK_LENGTH).to_i
  files_str = read(files_length, BLOCK_LENGTH)
  pos = files_length + BLOCK_LENGTH
  pos += BLOCK_LENGTH - pos % BLOCK_LENGTH unless pos % BLOCK_LENGTH == 0
  files_str.force_encoding(Encoding::UTF_8)
  files_str.each_line do |line|
    filename, length, offset = line.split("\t")
    @file_informations[filename] = [length.to_i, offset.to_i + pos]
  end
  @fullpath_files = @file_informations.transform_keys { |k| File.expand_path(k) }
end

.exist_in_datafile?(filename) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/neri/runtime.rb', line 108

def exist_in_datafile?(filename)
  file_information(filename) != nil
end

.file_exist?(filename) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/neri/runtime.rb', line 93

def file_exist?(filename)
  exist_in_datafile?(filename) || File.exist?(filename)
end

.file_read(filename, encoding = Encoding::BINARY) ⇒ Object



97
98
99
100
101
102
# File 'lib/neri/runtime.rb', line 97

def file_read(filename, encoding = Encoding::BINARY)
  filename = filename.encode(Encoding::UTF_8)
  length, offset = file_information(filename)
  str = length ? read(length, offset) : File.binread(filename)
  str.force_encoding(encoding)
end

.filesObject



104
105
106
# File 'lib/neri/runtime.rb', line 104

def files
  @file_informations.keys
end

.key=(key) ⇒ Object



48
49
50
# File 'lib/neri/runtime.rb', line 48

def key=(key)
  @xor ||= key.scan(/../).map { |a| a.to_i(16) }.pack("c*")
end

.load(file, priv = false) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/neri/runtime.rb', line 77

def load(file, priv = false)
  file_path = Pathname.new(file.encode(Encoding::UTF_8))
  path_str = search_in_load_path(file_path) if file_path.relative? && !file.start_with?(".")
  path_str ||= path_in_datafile(file_path)

  return neri_original_load(file, priv) unless path_str

  code = load_code(path_str)
  if priv
    Module.new.module_eval(code, path_str)
  else
    eval(code, TOPLEVEL_BINDING, path_str)
  end
  true
end

.require(feature) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/neri/runtime.rb', line 57

def require(feature)
  feature_path = Pathname.new(feature.encode(Encoding::UTF_8))
  feature_path = feature_path.sub_ext(".rb") if feature_path.extname == ""
  return neri_original_require(feature) if feature_path.extname == ".so"

  path_str = if feature_path.absolute? || feature.start_with?(".")
               path_in_datafile(feature_path)
             else
               search_in_load_path(feature_path)
             end

  return neri_original_require(feature) unless path_str
  return false if $LOADED_FEATURES.index(path_str)

  code = load_code(path_str)
  eval(code, TOPLEVEL_BINDING, path_str)
  $LOADED_FEATURES.push(path_str)
  true
end

.virtual_directory=(path) ⇒ Object



52
53
54
55
# File 'lib/neri/runtime.rb', line 52

def virtual_directory=(path)
  @virtual_directory = path
  @virtual_files = @file_informations.transform_keys { |k| File.expand_path(k, path) }
end