Skip to content

Commit fd843e3

Browse files
authored
Merge pull request #126 from pedrozath/master
Adds the run-app command to override the sketch wrapping
2 parents 9790dca + 9a70db0 commit fd843e3

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

lib/ruby-processing/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def mix_proxy_into_inner_classes
158158
klass.constants.each do |name|
159159
const = klass.const_get name
160160
next if const.class != Class || const.to_s.match(/^Java::/)
161-
const.class_eval 'include Processing::Proxy'
161+
const.class_eval('include Processing::Proxy')
162162
end
163163
end
164164

lib/ruby-processing/runner.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Runner
3333
Examples:
3434
rp5 setup unpack_samples
3535
rp5 run rp_samples/samples/contributed/jwishy.rb
36+
rp5 run-app rp_samples/samples/contributed/jwishy.rb
3637
rp5 create some_new_sketch 640 480 p3d (P3D mode example)
3738
rp5 create some_new_sketch 640 480 --wrap (a class wrapped default sketch)
3839
rp5 watch some_new_sketch.rb
@@ -63,14 +64,15 @@ def self.execute
6364
# Dispatch central.
6465
def execute!
6566
case @options.action
66-
when 'run' then run(@options.path, @options.args)
67-
when 'watch' then watch(@options.path, @options.args)
68-
when 'live' then live(@options.path, @options.args)
69-
when 'create' then create(@options.path, @options.args)
70-
when 'app' then app(@options.path)
71-
when 'setup' then setup(@options.path)
72-
when /-v/ then show_version
73-
when /-h/ then show_help
67+
when 'run' then run(@options.path, @options.args)
68+
when 'run-app' then run_app(@options.path, @options.args)
69+
when 'watch' then watch(@options.path, @options.args)
70+
when 'live' then live(@options.path, @options.args)
71+
when 'create' then create(@options.path, @options.args)
72+
when 'app' then app(@options.path)
73+
when 'setup' then setup(@options.path)
74+
when /-v/ then show_version
75+
when /-h/ then show_help
7476
else
7577
show_help
7678
end
@@ -103,6 +105,11 @@ def run(sketch, args)
103105
spin_up('run.rb', sketch, args)
104106
end
105107

108+
def run_app(sketch, args)
109+
ensure_exists(sketch)
110+
spin_up('run_app.rb', sketch, args)
111+
end
112+
106113
# Run a sketch, keeping an eye on it's file, and reloading
107114
# whenever it changes.
108115
def watch(sketch, args)

lib/ruby-processing/runners/base.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,23 @@ def setup
2626
EOS
2727

2828
# This method is the common entry point to run a sketch, bare or complete.
29+
30+
def self.run_app
31+
load SKETCH_PATH
32+
Processing::App.sketch_class.new unless $app
33+
end
34+
2935
def self.load_and_run_sketch
3036
source = read_sketch_source
3137
wrapped = !source.match(/^[^#]*< Processing::App/).nil?
3238
no_methods = source.match(/^[^#]*(def\s+setup|def\s+draw)/).nil?
3339
if wrapped
34-
load SKETCH_PATH
35-
Processing::App.sketch_class.new unless $app
40+
run_app
3641
return
3742
end
38-
code = no_methods ? format(NAKED_WRAP, source) : format(BARE_WRAP, source)
39-
Object.class_eval code, SKETCH_PATH, -1
43+
Object.class_eval(code, SKETCH_PATH, -1)
4044
Processing::App.sketch_class.new
45+
code = no_methods ? format(NAKED_WRAP, source) : format(BARE_WRAP, source)
4146
end
4247

4348
# Read in the sketch source code. Needs to work both online and offline.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require_relative 'base'
2+
3+
Processing.run_app

0 commit comments

Comments
 (0)