lib/crystalruby/templates/function.cr in crystalruby-0.2.2 vs lib/crystalruby/templates/function.cr in crystalruby-0.3.0

- old
+ new

@@ -1,12 +1,12 @@ # This is the template used for all CrystalRuby functions # Calls to this method *from ruby* are first transformed through the lib function. # Crystal code can simply call this method directly, enabling generated crystal code # to call other generated crystal code without overhead. -module %{module_name} - def self.%{fn_name}(%{fn_args}) : %{fn_ret_type} +%{module_or_class} %{module_name} %{superclass} + def %{fn_scope}%{fn_name}(%{fn_args}) : %{fn_ret_type} %{fn_body} end end # This function is the entry point for the CrystalRuby code, exposed through FFI. @@ -14,17 +14,17 @@ # to ensure that we are using Crystal native types. fun %{lib_fn_name}(%{lib_fn_args}): %{lib_fn_ret_type} begin %{convert_lib_args} begin - return_value = %{module_name}.%{fn_name}(%{arg_names}) + return_value = %{receiver}.%{fn_name}(%{arg_names})%{block_converter} return %{convert_return_type} rescue ex - CrystalRuby.report_error("RuntimeError", ex.message.to_s, 0) + CrystalRuby.report_error("RuntimeError", ex.message.to_s, ex.backtrace.to_json, 0) end rescue ex - CrystalRuby.report_error("ArgumentError", ex.message.to_s, 0) + CrystalRuby.report_error("ArgumentError", ex.message.to_s, ex.backtrace.to_json, 0) end return %{error_value} end @@ -35,28 +35,29 @@ begin %{convert_lib_args} CrystalRuby.increment_task_counter spawn do begin - return_value = %{module_name}.%{fn_name}(%{arg_names}) - converted = %{convert_return_type} + return_value = %{receiver}.%{fn_name}(%{arg_names})%{block_converter} CrystalRuby.queue_callback(->{ + converted = %{convert_return_type} %{callback_call} CrystalRuby.decrement_task_counter }) rescue ex exception = ex.message.to_s + backtrace = ex.backtrace.to_json CrystalRuby.queue_callback(->{ - CrystalRuby.error_callback.call("RuntimeError".to_unsafe, exception.to_unsafe, thread_id) + CrystalRuby.report_error("RuntimeError", exception, backtrace, thread_id) CrystalRuby.decrement_task_counter }) end end rescue ex - exception = ex.message.to_s + backtrace = ex.backtrace.to_json CrystalRuby.queue_callback(->{ - CrystalRuby.error_callback.call("RuntimeError".to_unsafe, ex.message.to_s.to_unsafe, thread_id) + CrystalRuby.report_error("RuntimeError", ex.message.to_s, backtrace, thread_id) CrystalRuby.decrement_task_counter }) end end