SwagColoredKitteh / shiny-pancake

A renderer that takes commands from standard input. Though, it turned more into a kind of replay viewer.
GNU General Public License v3.0
6 stars 1 forks source link

importing from an external file #13

Open MarcosCosmos opened 7 years ago

MarcosCosmos commented 7 years ago

Fairly straight forward, importing from other files helps with #12 as we can all just share a repo of definitions for each game.

Debatable:

SwagColoredKitteh commented 7 years ago

I guess this could be done with #IMPORT <FILE>. Shouldn't be too hard once the code gets cleaned up a bit. Will need a separate function for reading the files. Something like fn read_from<R: BufRead>(&mut self, from: &mut R) on a Context struct or so, which holds the current rendering state like colors, variables, etc.

MarcosCosmos commented 7 years ago

pretty much what I had in mind - although my instinct is to have the reader be a seperate function rather than a member function. Couple of considerations:

If we want to potentially support nested contexts, then it should be a member method, though?

SwagColoredKitteh commented 7 years ago

We could also have the Context as a struct without any methods on it, then pass it wherever it's needed. The alternative would be to put the variables and macros in the reader, which feels ugly to me.

SwagColoredKitteh commented 7 years ago

So, something like this:

struct Context {
    variables: BTreeMap<String, String>, // or whatever other representation we will use for variables
    macros: BTreeMap<String, Macro>
}