m2stp – Simple text processing module

About Monkey 2 Forums Monkey 2 Projects m2stp – Simple text processing module

This topic contains 6 replies, has 4 voices, and was last updated by  cocon 1 year, 4 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #13204


    m2stp is a text processing module for Monkey2.
    It takes a string and translates special text and symbols into whatever you want in real-time.

    GitHub: https://github.com/Hezkore/m2stp

    * Download or Git Clone to your Monkey2 ‘Modules’ folder
    * Recompile module
    * Compile & run tests inside the ‘tests’ folder

    Possible usage
    For example You have %health% health could perhaps turn into You have 100% health
    Or Today is %day% could be turned into Today is Monday

    This all happens outside of the compiling process.
    Which means you can use external script files to run these kinds of things and change them on the fly.
    You can let the user define how things should act and look without even restarting the application, and certainly without recompiling the project.

    It’s also got support for functions.
    So for example 1+4=$add(1,4) would return 1+4=5

    You can combine variables and multiple functions as you like.
    $add(%var_a%,%var_b%) or even $add($add(%var_a%,1),%var_b%)

    It comes with a few base functions and one variable (for checking version)
    But you can add as many as you like or need.
    ‘Test3’ shows how you can skip all the base functions and add your own ones.

    It’s pretty basic at the moment.
    But you could extend it quite a lot with functions.
    For example $if, $ifgreater $ifless could be added to conditionally execute statements.
    So for a media player displaying song length via %time% you could do $ifgreater(%time%,5,Over 5 minutes long!)

    The idea is to use it for everything string related that should be customizable by the user.
    For example how an IRC client displays names, or a media player handles titles and album names.
    But it’s not what I’d call a “script” language, even though it runs from user scripts.

    Oh and you can use ‘ as an escape character.
    So  '$add(%value%,1)' would actually print that and not call the function nor variable.
    Use ”’ to print a single ‘

    You can change all the symbols as well.
    By default % are variables and $ are functions and ' are escape characters.




    Formatting? Processing! 🙂



    Heh yeah maybe I should rename it. 🙂
    Most other applications I’ve used with these kinds of things have called it “formatting”, so I just went with that. ¯\_(ツ)_/¯

    A good use would perhaps be for Ted2Go’s output folder.
    So instead of it always building to “<title>.buildv<m2ver>” it could use this and the users themselves could decide where they want the output.
    For example %source_title%.buildv%m2cc_version% would be the same as what we have now.
    But I’d probably want something like $if(%source_folder_name%,"src",../output,output) where it would just output to the folder “output” but if it’s inside a folder called “src” I’d want the output to instead be in the previous folder, so not to clutter up the “src” folder.

    Same for the product folder.



    That’s cool. Thanks. Gonna try it out now.




    I don’t know if it would be better roll with the formatting capabilities of the standard library, just to save effort. But any other than that, this code has lots of potential to be customized for further uses or be extended for more string processing capabilities, it acts also as an educational project. 🙂



    @cocon hmm I’m not sure what you mean.
    You can not load a .txt or any other external files and have Monkey2 process them in real time with any of the standard libs.
    Because there’s no library in Monkey2 that handles string processing outside of the compiling process.
    Monkey2 only does stuff when compiling, this module does it in real-time.

    The idea is that you’d write your little “script” in something like “myScript.txt” and then load that into Monkey2.
    Then if the user don’t like how the script acts, they could change it! 🙂
    And they wouldn’t have to recompile the entire thing, in fact they don’t even need the source code.
    They just need the little script.

    So in Ted2Go for the output/product folder, right now I’d have to recompile the entire Ted2Go project to change that.
    But if it used this module, the user could change that without even restarting Ted2Go.

    I’ve added “Test4” to show this better.

    On another topic.
    I’ve moved this thread to the Code Library instead.



    Oh, I left the previous message very abstract… I meant about the capabilities of the C standard library, where basically you would create a beefed-up wrapper around printf. But anyway it seems that you are up to something completely different here, it reminds me of the beginnings of a DSL, right? 🙂

    P.S. Can you move threads? There are a few of mine I would like to move as well.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.