Skip to content

Commit

Permalink
Rename RubyRubyScript
Browse files Browse the repository at this point in the history
Matches `CSharpScript`; `Ruby` alone isn’t descriptive, is it?
  • Loading branch information
ParadoxV5 committed Sep 24, 2023
1 parent 9b58bd9 commit dc7767f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
12 changes: 6 additions & 6 deletions docs/RubyLanguage.puml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ participant lang [
]
participant script [
Script
(""Godot::Ruby""
(""Godot::RubyScript""
instance)
]
participant class [
Expand All @@ -39,7 +39,7 @@ godot -> lang: ""godot_rb_setup""
create instance
script -> instance: ""instance_create""
return ""ScriptInstancePtr(RubyLanguage)""
return ""Ruby(RubyLanguage)""
return ""RubyScript(RubyLanguage)""
return ""register_""\n""script_language""

newpage Load ""script.rb""
Expand All @@ -51,11 +51,11 @@ godot -> lang: ""create_script""
script -> script: ""set_script""
create instance
script -> instance: ""instance_create""
return ""ScriptInstancePtr(Ruby)""
return ""Ruby(Ruby)""
return ""ScriptInstancePtr(RubyScript)""
return ""RubyScript(RubyScript)""

return ""self""
return ""Godot::Ruby""
return ""Godot::RubyScript""


godot -> script: load
Expand All @@ -72,7 +72,7 @@ godot -> script: ""new""
object -> godot: ""super""
return Blank-slate, script-less ""Godot::Object""
object -> godot: ""set_script""
godot -> instance: ""ScriptInstancePtr(Ruby).instance_create""
godot -> instance: ""ScriptInstancePtr(RubyScript).instance_create""
instance -> script: ""instance_create""
script -> object: Protect from GC
return
Expand Down
18 changes: 9 additions & 9 deletions lib/godot/ruby_language.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Godot
module Ruby::Autoloads
module RubyScript::Autoloads
public_class_method :remove_const
Godot.include self
end
Expand All @@ -12,8 +12,8 @@ class << RubyLanguage = ScriptLanguageExtension.new
# TODO: don’t generate a new {Variant} on every call

def _get_name = 'Ruby'
#TODO: can this be `'Godot::Ruby'`?
def _get_type = 'Ruby'
#TODO: can this be `'Godot::RubyScript'`?
def _get_type = 'RubyScript'
def _get_extension = 'rb'
def _get_recognized_extensions = PackedStringArray.from %w[rb rbw gemspec]
def _get_comment_delimiters = PackedStringArray['#'] # What `=begin`-`=end`?
Expand All @@ -30,10 +30,10 @@ def _has_named_classes = false
def _add_global_constant(name, value)
value and add_named_global_constant(name, value)
end
def _add_named_global_constant(name, value) = Ruby::Autoloads.const_set(name, value)
def _remove_named_global_constant(name) = Ruby::Autoloads.remove_const(name)
def _add_named_global_constant(name, value) = RubyScript::Autoloads.const_set(name, value)
def _remove_named_global_constant(name) = RubyScript::Autoloads.remove_const(name)

def _create_script = Ruby.new
def _create_script = RubyScript.new
# !
# Dictionary _get_global_class_name ( String path ) virtual const
#
Expand Down Expand Up @@ -87,13 +87,13 @@ def _create_script = Ruby.new
# Error _open_in_external_editor ( ScriptExtension script, int line, int column ) virtual
# bool _supports_builtin_mode ( ) virtual const

class << Ruby::RubyLanguage = Ruby.new(self)
class << RubyScript::RubyLanguage = RubyScript.new(self)
def _can_instantiate = false
def new = klass.attached_object
end
def get_script = Ruby::RubyLanguage
def get_script = RubyScript::RubyLanguage
# Recreate {#initialize} #TODO: `__send__(:initialize)`
attached_object.set_script Ruby::RubyLanguage
attached_object.set_script RubyScript::RubyLanguage
end

Engine.register_script_language(RubyLanguage) # TODO: raise Error Enum
Expand Down
4 changes: 2 additions & 2 deletions lib/godot/ruby.rb → lib/godot/ruby_script.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module Godot
class Ruby < ScriptExtension
class RubyScript < ScriptExtension
# The parsed class, which may be de-sync with {#source_code} until {#_reload}ed
attr_reader :klass
def initialize(klass = nil)
Expand All @@ -10,7 +10,7 @@ def initialize(klass = nil)
end

# The script for the 5head self-implementation
Ruby = new(self)
RubyScript = new(self)

# The Godot Editor pass entire source code( references)s around to enable IDE capabilities independent of the disk
attr_accessor :source_code
Expand Down
8 changes: 4 additions & 4 deletions sig/ruby_language.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ module Godot
def self._add_named_global_constant: (interned name, variant_like value) -> variant_like
def self._remove_named_global_constant: (interned name) -> top

def _create_script: () -> Ruby[Object]
def _create_script: () -> RubyScript[Object]
end
RubyLanguage: ScriptLanguageExtension

class Ruby[C < Object]
class RubyScript[C < Object]
module Autoloads
public def self.remove_const: (interned name) -> top
end
RubyLanguage: Ruby[ScriptLanguageExtension]
RubyLanguage: RubyScript[ScriptLanguageExtension]
end
include Ruby::Autoloads
include RubyScript::Autoloads
end
4 changes: 2 additions & 2 deletions sig/ruby.rbs → sig/ruby_script.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Godot
# until we have RBS integration
class ScriptExtension < Object end

class Ruby[C < Object] < ScriptExtension
Ruby: Ruby[Ruby[untyped]]
class RubyScript[C < Object] < ScriptExtension
RubyScript: RubyScript[RubyScript[untyped]]

attr_reader klass: singleton(Object)? # https://github.com/ruby/rbs/issues/1542
def initialize: (?singleton(Object)?) -> void
Expand Down
32 changes: 17 additions & 15 deletions src/ruby/ruby_language.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ const GDExtensionScriptInstanceInfo godot_rb_script_instance_info = {

GDExtensionInterfaceScriptInstanceCreate script_instance_create;
/** @return {GDExtensionScriptInstancePtr} in {Variant} form */
VALUE gocot_rb_cRuby_i_instance_create(VALUE self, VALUE for_object) {
//TODO: Check superclass
VALUE gocot_rb_cRubyScript_i_instance_create(
RB_UNUSED_VAR(VALUE self), //FIXME: Check superclass
VALUE for_object
) {
rb_gc_register_mark_object(for_object); // Let Godot Engine lock GC
GDExtensionVariantPtr script_instance = godot_rb_variant_alloc();
godot_rb_gdextension.variant_from_object_ptr(
Expand All @@ -143,36 +145,36 @@ VALUE gocot_rb_cRuby_i_instance_create(VALUE self, VALUE for_object) {
}


VALUE cRuby_script, cRuby, RubyLanguage_script, RubyLanguage;
VALUE cRubyScript_RubyScript, cRubyScript, cRubyScript_RubyLanguage, RubyLanguage;

void godot_rb_init_RubyLanguage(void) {
gdext_variant_new_copy = (GDExtensionInterfaceVariantNewCopy)godot_rb_get_proc("variant_new_copy");
script_instance_create = (GDExtensionInterfaceScriptInstanceCreate)godot_rb_get_proc("script_instance_create");
ID idRuby = rb_intern("Ruby"), idRubyLanguage = rb_intern("RubyLanguage");
ID idRubyScript = rb_intern("RubyScript"), idRubyLanguage = rb_intern("RubyLanguage");

godot_rb_require_relative(ruby);
cRuby = rb_const_get_at(godot_rb_mGodot, idRuby);
rb_define_method(cRuby, "_instance_create", gocot_rb_cRuby_i_instance_create, 1);
godot_rb_require_relative(ruby_script);
cRubyScript = rb_const_get_at(godot_rb_mGodot, idRubyScript);
rb_define_method(cRubyScript, "_instance_create", gocot_rb_cRubyScript_i_instance_create, 1);
godot_rb_require_relative(ruby_language);
RubyLanguage = rb_const_get_at(godot_rb_mGodot, idRubyLanguage);
godot_rb_gdextension.object_ptr_from_variant(
&godot_rb_RubyLanguage_object,
godot_rb_cVariant_get_variant(RubyLanguage)
);

cRuby_script = rb_const_get_at(cRuby, idRuby);
RubyLanguage_script = rb_const_get_at(cRuby, idRubyLanguage);
cRubyScript_RubyScript = rb_const_get_at(cRubyScript, idRubyScript);
cRubyScript_RubyLanguage = rb_const_get_at(cRubyScript, idRubyLanguage);
// Lock these from the GC – too important to be accidentally GC-ed
rb_gc_register_mark_object(cRuby_script);
rb_gc_register_mark_object(cRuby);
rb_gc_register_mark_object(RubyLanguage_script);
rb_gc_register_mark_object(cRubyScript_RubyScript);
rb_gc_register_mark_object(cRubyScript);
rb_gc_register_mark_object(cRubyScript_RubyLanguage);
rb_gc_register_mark_object(RubyLanguage);
}

void godot_rb_destroy_RubyLanguage(void) {
//TODO: https://docs.godotengine.org/en/stable/classes/class_engine.html#class-engine-method-unregister-script-language
rb_gc_unregister_address(&RubyLanguage);
rb_gc_unregister_address(&RubyLanguage_script);
rb_gc_unregister_address(&cRuby);
rb_gc_unregister_address(&cRuby_script);
rb_gc_unregister_address(&cRubyScript_RubyLanguage);
rb_gc_unregister_address(&cRubyScript);
rb_gc_unregister_address(&cRubyScript_RubyScript);
}

0 comments on commit dc7767f

Please sign in to comment.