summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Black <[email protected]>2018-02-25 17:18:27 -0800
committerTom Black <[email protected]>2018-05-06 16:53:21 -0700
commit89b931a9325db2623490bf5f99672213b600e10e (patch)
tree443c4e46ea10eee3f8dd07d81429742c656cc92a
parent7d3cff5e5d6d53d7f4def94a9dc831e099e03e67 (diff)
downloadruby2d-89b931a9325db2623490bf5f99672213b600e10e.tar.gz
ruby2d-89b931a9325db2623490bf5f99672213b600e10e.zip
Fix native building of apps
-rwxr-xr-xbin/ruby2d18
-rw-r--r--ext/ruby2d/ruby2d.c30
-rw-r--r--lib/ruby2d/window.rb1
3 files changed, 35 insertions, 14 deletions
diff --git a/bin/ruby2d b/bin/ruby2d
index 5c11a67..d7b1e15 100755
--- a/bin/ruby2d
+++ b/bin/ruby2d
@@ -60,8 +60,8 @@ def make_lib
end
lib << "
-include Ruby2D::DSL
-include Ruby2D\n"
+include Ruby2D
+extend Ruby2D::DSL\n"
File.write('build/lib.rb', lib)
end
@@ -87,13 +87,16 @@ def build_native(rb_file)
exit
end
+ # Add debugging information to produce backtrace
+ if @debug then debug_flag = '-g' end
+
# Assemble the Ruby 2D library in one `.rb` file and compile to bytecode
make_lib
- `mrbc -Bruby2d_lib -obuild/lib.c build/lib.rb`
+ `mrbc #{debug_flag} -Bruby2d_lib -obuild/lib.c build/lib.rb`
# Read the provided Ruby source file, copy to build dir and compile to bytecode
File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
- `mrbc -Bruby2d_app -obuild/src.c build/src.rb`
+ `mrbc #{debug_flag} -Bruby2d_app -obuild/src.c build/src.rb`
# Combine contents of C source files and bytecode into one file
open('build/app.c', 'w') do |f|
@@ -165,13 +168,16 @@ def build_apple(rb_file, device)
exit
end
+ # Add debugging information to produce backtrace
+ if @debug then debug_flag = '-g' end
+
# Assemble the Ruby 2D library in one `.rb` file and compile to bytecode
make_lib
- `mrbc -Bruby2d_lib -obuild/lib.c build/lib.rb`
+ `mrbc #{debug_flag} -Bruby2d_lib -obuild/lib.c build/lib.rb`
# Read the provided Ruby source file, copy to build dir and compile to bytecode
File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
- `mrbc -Bruby2d_app -obuild/src.c build/src.rb`
+ `mrbc #{debug_flag} -Bruby2d_app -obuild/src.c build/src.rb`
# Copy over iOS project
FileUtils.cp_r "#{@gem_dir}/assets/#{device}", "build"
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index 2daa7ed..24c3857 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -62,8 +62,8 @@
#define r_ary_entry(ary, pos) mrb_ary_entry(ary, pos)
#define r_data_wrap_struct(name, data) mrb_obj_value(Data_Wrap_Struct(mrb, mrb->object_class, &name##_data_type, data))
#define r_data_get_struct(self, var, mrb_type, rb_type, data) Data_Get_Struct(mrb, r_iv_get(self, var), mrb_type, data)
- #define r_define_module(name) mrb_module_get(mrb, name)
- #define r_define_class(module, name) mrb_class_get_under(mrb, module, name)
+ #define r_define_module(name) mrb_define_module(mrb, name)
+ #define r_define_class(module, name) mrb_define_class_under(mrb, module, name, mrb->object_class)
#define r_define_method(class, name, function, args) mrb_define_method(mrb, class, name, function, args)
#define r_args_none (MRB_ARGS_NONE())
#define r_args_req(n) MRB_ARGS_REQ(n)
@@ -919,11 +919,27 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
S2D_Diagnostics(true);
}
- // Load controller mappings, if DB file exists
- char *controller_mappings_path = RSTRING_PTR(r_iv_get(self, "@controller_mappings_path"));
- if (S2D_FileExists(controller_mappings_path)) {
- S2D_LoadControllerMappingsFromFile(controller_mappings_path);
- }
+ // Load controller mappings
+ #if !RUBY2D_IOS_TVOS && !WINDOWS
+ #include <pwd.h>
+
+ char *homedir;
+ if ((homedir = getenv("HOME")) == NULL) {
+ homedir = getpwuid(getuid())->pw_dir;
+ }
+
+ char *mappings = "/.ruby2d/controllers.txt";
+ char *full_mappings_path = malloc(strlen(homedir) + strlen(mappings) + 1);
+ strcpy(full_mappings_path, homedir); strcat(full_mappings_path, mappings);
+ printf("%s\n", full_mappings_path);
+
+ // Load controller mappings, if DB file exists
+ if (S2D_FileExists(full_mappings_path)) {
+ S2D_LoadControllerMappingsFromFile(full_mappings_path);
+ }
+
+ free(full_mappings_path);
+ #endif
// Get window attributes
char *title = RSTRING_PTR(r_iv_get(self, "@title"));
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index 84d7c3f..686c6b0 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -48,7 +48,6 @@ module Ruby2D
}
@update_proc = Proc.new {}
@diagnostics = false
- @controller_mappings_path = File.join(Dir.home, ".ruby2d", "controllers.txt")
end
def new_event_key