Jump to content




brick-like CLI utility/framework


  • You cannot reply to this topic
No replies to this topic

#1 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 07 December 2016 - 09:24 PM

Would anyone be interested in some brick-like framework/utility/whatever-you-call-it?

Here is a simple example game (guess-the-number) which is using this script (Which I dubbed "Renga": That's Japanese for "brick")
Posted Image
And here is the corresponding code:
Spoiler

Some things you might notice in this code example are:
  • There are custom functions like "Center" which, well... renders the text at the center of the screen, I guess
  • Strings written to the terminal using "Center" allow you to automatically interpolate from the state
  • The UI is separated from the logic itself
Now some stuff you might not know:
The state is the only thing persisting between the UI and the logic. Everything else is(/should be) local to the function and won't leak outside. If you try to set a value in the state to something else it also typechecks so you can't sneak in some weird type changes. This won't eliminate the problem with types entirely, but at least enforce consistent types used for the main "state" of the program. "nil" translates to "use the value from the last state" when returning a new state in the logic function.
Thanks to this "state enforcement" debugging programs using this becomes a breeze because you are able to store the states in a history and effectively "roll back the time". Or make it run step-wise.

Every input would be appreciated!

Edited by H4X0RZ, 07 December 2016 - 09:31 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users