Class: Gap::Maker
- Inherits:
-
Object
- Object
- Gap::Maker
- Defined in:
- lib/gap50/samsara/maker.rb
Constant Summary collapse
- RND =
Random.new
Instance Attribute Summary collapse
-
#sam ⇒ Object
Returns the value of attribute sam.
-
#teardown ⇒ Object
Returns the value of attribute teardown.
-
#temp ⇒ Object
Returns the value of attribute temp.
Instance Method Summary collapse
- #asBase64 ⇒ Object
- #asMarshal ⇒ Object
- #copyfile(src, dest) ⇒ Object (also: #COPY)
- #exec(cmd) ⇒ Object (also: #RUN)
- #from(name) ⇒ Object (also: #FROM)
- #genlib(name, text) ⇒ Object (also: #CXX)
-
#initialize(sam = nil, temp = genname, &block) ⇒ Maker
constructor
A new instance of Maker.
- #path(name) ⇒ Object
- #readfile(name) ⇒ Object (also: #READ)
- #tear ⇒ Object
- #transaction ⇒ Object
- #writefile(name, value) ⇒ Object (also: #WRITE)
Constructor Details
#initialize(sam = nil, temp = genname, &block) ⇒ Maker
Returns a new instance of Maker.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gap50/samsara/maker.rb', line 7 def initialize(sam = nil, temp = genname, &block) @sam = sam @temp = temp if defined? instance_exec transaction do |m| instance_exec &block end else transaction do |m| instance_eval &block end end end |
Instance Attribute Details
#sam ⇒ Object
Returns the value of attribute sam.
4 5 6 |
# File 'lib/gap50/samsara/maker.rb', line 4 def sam @sam end |
#teardown ⇒ Object
Returns the value of attribute teardown.
4 5 6 |
# File 'lib/gap50/samsara/maker.rb', line 4 def teardown @teardown end |
#temp ⇒ Object
Returns the value of attribute temp.
4 5 6 |
# File 'lib/gap50/samsara/maker.rb', line 4 def temp @temp end |
Instance Method Details
#asBase64 ⇒ Object
53 54 55 56 |
# File 'lib/gap50/samsara/maker.rb', line 53 def asBase64 _import_all @sam.toBase64 end |
#asMarshal ⇒ Object
58 59 60 61 |
# File 'lib/gap50/samsara/maker.rb', line 58 def asMarshal _import_all @sam.toMarshal end |
#copyfile(src, dest) ⇒ Object Also known as: COPY
37 38 39 |
# File 'lib/gap50/samsara/maker.rb', line 37 def copyfile(src, dest) writefile dest, @sam.readfile(src) end |
#exec(cmd) ⇒ Object Also known as: RUN
41 42 43 |
# File 'lib/gap50/samsara/maker.rb', line 41 def exec(cmd) system "cd #{@temp} && #{cmd}" end |
#from(name) ⇒ Object Also known as: FROM
70 71 72 73 |
# File 'lib/gap50/samsara/maker.rb', line 70 def from(name) @sam = Samsara.new name _export_all end |
#genlib(name, text) ⇒ Object Also known as: CXX
63 64 65 66 67 68 |
# File 'lib/gap50/samsara/maker.rb', line 63 def genlib(name, text) writefile "cpp/#{name}.cpp", %{#define GAPI(type) extern "C" type __stdcall #{text} } exec "g++ cpp/#{name}.cpp -o cpp/#{name}.dll -static -s -shared -m32 -Wl,-add-stdcall-alias" end |
#path(name) ⇒ Object
21 22 23 |
# File 'lib/gap50/samsara/maker.rb', line 21 def path(name) @temp + "/" + name end |
#readfile(name) ⇒ Object Also known as: READ
25 26 27 |
# File 'lib/gap50/samsara/maker.rb', line 25 def readfile(name) @sam.readfile path(name) end |
#tear ⇒ Object
33 34 35 |
# File 'lib/gap50/samsara/maker.rb', line 33 def tear self.teardown = true end |
#transaction ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/gap50/samsara/maker.rb', line 45 def transaction _create ret = yield self _import_all unless self.teardown _cleanup ret end |
#writefile(name, value) ⇒ Object Also known as: WRITE
29 30 31 |
# File 'lib/gap50/samsara/maker.rb', line 29 def writefile(name, value) @sam.writefile path(name), value end |