Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Hotload contrib and other files from the DR install directory #92

Open
awfulcooking opened this issue Jun 25, 2021 · 0 comments

Comments

@awfulcooking
Copy link
Contributor

awfulcooking commented Jun 25, 2021

This would help for additions and modifications that developers find useful for their own workflow, as well as make it easier to work on this repo

A proposal would be to include a skeleton directory containing stubs corresponding to files in dragon/:

contrib/
  args.rb
  assert.rb
  console.rb
  (...)

And have the runtime a) hotload those files in development, loaded before game files, b) compile them in similar order on top of the baked-in contrib code.

Symlinking $dr_root/contrib/some_file.rb to a checkout outside of the directory could also work.

Example use case

#91 was extracted from a real-world override placed in app/lib/console.rb:

Expand
module GTK
  class Console
    def eval_the_set_command
      cmd = current_input_str.strip
      if cmd.length != 0
        @log_offset = 0
        prompt.clear

        @command_history.pop while @command_history.length >= @max_history
        @command_history.unshift cmd
        @command_history_index = -1
        @nonhistory_input = ''

        if cmd == 'quit' || cmd == ':wq' || cmd == ':q!' || cmd == ':q' || cmd == ':wqa'
          $gtk.request_quit
        else
          puts "-> #{cmd}"
          begin
            @last_command = cmd

            locals = (@locals ||= {})
            code = "
              #{
                locals.keys.map do |name|
                  "#{name} = locals[:#{name}]"
                end.join "\n"
              }

              _ = (#{cmd})

              local_variables.each do |name|
                locals[name] = eval(name.to_s)
              end

              _
            "

            result = $top_level.instance_eval code

            if result.nil?
              puts "=> nil"
            elsif result == :console_silent_eval
            else
              puts "=> #{result}"
            end
            @last_command_errored = false
          rescue Exception => e
            try_search_docs e
            puts  "* EXCEPTION: #{e}"
          end
        end
      end
    end
  end
end

But I found myself missing the override in other projects.

In order to share it, I'd have to symlink or copy it to each project, and add the require line to my code.

Together those bring enough impedence that I haven't done it for the smallest projects, but those stand to gain equally, if not moreso due to auto-inclusion being more powerful for rapid prototypes.

Related to #52

A reframing or extension of this could be a solution for Amir and Levi's config enhancement, discussed here: #52 (comment)

For example, all rb files under $dr_root/autoload could automatically required.

With a stub named config.rb showing some common overrides.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant