Basic interpreter with custom command

I expanded the BASIC script interpreter in http://8bitcoder.com/downloads/basicscript-02.zip to include an example of how you can extend the interpreter and add your own commands to it. Sorry about the Makefile depending on Qt. I’ll create a generic Makefile next version I release.

I created a ConsoleBasic object, then added the cls command. You can see I add it in the constructor, then in execAddonCommand I check the token that is passed in to figure out what command I should execute, which in this case can only be one command, then clear the screen via ANSI escape codes.

Next example will show how to make your C++ variables available to BASIC.

class ConsoleBasic : public SmallBasic
{
private:
    int m_cls;
public:
    ConsoleBasic(const char* pszFilename)
        : SmallBasic(pszFilename),m_cls(0)
    {
        m_cls = addCommand("cls");
    }

    bool execAddonCommand(const int tok)
    {
        if(tok == m_cls)
            printf("\x1b[2J\x1b[0;0H");
        return true;
    }
};