[WIP]Lua JASS Generation Framework

Nestharus

o-o
Reaction score
84
Ok, been working on Lua JASS Framework ; )

This specializes in generating JASS for a map within WE!

First, solving the issue of collision between files to be imported as JASS.

Obvious fix-
MapName.CodeName

Name of the map can't be retrieved via Lua, so this raises the need for a req'd FILE_INFORMATION text macro.

JASS:

//! textmacro FILE_INFORMATION
    //! i local FILE_NAME = "Map Name"
//! endtextmacro


From here, there need to be functions to automatically create the files in the right directory following the naming convention, so come to the GENERATE_JASS macro.

JASS:

//! textmacro GENERATE_JASS takes CODE_NAME
    //! i do
        //! i local jass
        
        //! i local function writeJASS(code)
            //! i if type(code) == "table" then
                //! i for i,v in ipairs(code) do
                    //! i writeJASS(v)
                //! i end
            //! i else
                //! i jass:write(code .. "\n")
            //! i end
        //! i end
        
        //! i function generateJASS(jassCode)
            //! i local code = jassCode
            //! i jass = assert(io.open("jass\\" .. FILE_NAME .. "." .. "$CODE_NAME$", "w"))
                //! i writeJASS(code)
            //! i jass:close()
        //! i end
    //! i end
//! endtextmacro


The only public function above is generateJASS, which takes the JASS code to generate. The JASS code can either be passed in as a string or a table. The table may have infinite strings and tables within it.

So, the current JASS Lua area looks like this for a given block of Lua code-
JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro FILE_INFORMATION()
    //! runtextmacro GENERATE_JASS("Code Name")
//! endexternalblock


And how about an example for passing a string into generateJASS

JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro FILE_INFORMATION()
    //! runtextmacro GENERATE_JASS("Code Name")

    //! i generateJASS([[
        //! i struct Hello extends array
            //! i public static method onInit takes nothing returns nothing
                //! i //! runtextmacro WooWoo()
            //! i endmethod
        //! i endstruct
        //! i //! textmacro WooWoo
            //! i call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Hello World!")
        //! i //! endtextmacro
    //! i ]])
//! endexternalblock



Obviously strings are hard to handle, so tables are a better bet in most cases, but having a huge table is difficult to mess with and can be cumbersome. Dealing with a deep multi dimensional table can also be insane when you have a billion [].

So we have a third macro called LEXICAL_JASS which makes it easy to manipulate JASS and provides a clean syntax to do it.

A look at that exact same Lua section using Lexical JASS.

JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro FILE_INFORMATION()
    //! runtextmacro GENERATE_JASS("Code Name")
    //! runtextmacro LEXICAL_JASS()

    //! i lexical.add([[struct Hello extends array]])
    //! i lexical.open()
        //! i lexical.add([[public static method onInit takes nothing returns nothing]])
        //! i lexical.open()
            //! i lexical.add([[//! runtextmacro WooWoo()]])
        //! i lexical.close()
        //! i lexical.add([[endmethod]])
    //! i lexical.close()
    //! i lexical.add([[endstruct]])
    //! i lexical.add([[//! textmacro WooWoo]])
    //! i lexical.open()
        //! i lexical.add([[call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Hello World!")]])
    //! i lexical.close()
    //! i lexical.add([[//! endtextmacro]])
    
    //! i generateJASS(lexical.code())
//! endexternalblock


As you add elements, you can store those elements into a var-
[ljass]lexical.element()[/ljass]

So what this means is as you are building up the sections, if you want to be able to manipulate a section later or let someone else do it, you can pass them the element =).

So, here's a look at the LEXICAL_JASS macro

JASS:

//! textmacro LEXICAL_JASS
    //! i local lexical = {}
    //! i do
        //! i local lexicalJASS = {}
        //! i local upLexical = {}
        //! i local curLexical = lexicalJASS
        
        //used to open lexical elements, like functions, structs, etc
        //! i lexical.open = function()
            //! i table.insert(upLexical, curLexical)
            //! i table.insert(curLexical, {})
            //! i curLexical = curLexical[#curLexical]
        //! i end
        
        //used to close lexical elements
        //! i lexical.close = function()
            //! i curLexical = upLexical[#upLexical]
            //! i table.remove(upLexical)
        //! i end
        
        //used to just add a line
        //! i lexical.add = function(line, theLexical)
            //! i table.insert(theLexical or curLexical, line)
        //! i end
        
        //used to get the current lexical element (useful for adding to them later on)
        //! i lexical.element = function()
            //! i return curLexical
        //! i end
        
        //! i lexical.code = function()
            //! i return lexicalJASS
        //! i end
    //! i end
//! endtextmacro


The reason that lexical is defined at the top and is local is so that you can have different libraries or w/e with their own lexical things and maintain their scopes =).

To get JASS in map-
JASS:

//! import "MapName.CodeName"



So, given I work on this some more, I'd like to hopefully make this the standard for generating JASS for maps via Lua ^_-.
 

Nestharus

o-o
Reaction score
84
>Maybe I'm daft, but can someone please remind me why we need this at all?

Amazing preprocessing power for super efficient powerful utility, system, and framework design.
 

Nestharus

o-o
Reaction score
84
Look at the lexical jass portion and u'll totally get why I'd want to use this over cJASS definitions, lol.

Remember that each open element can be retrieved and stored into a variable making editing of each lexical portion super easy ><. You could have users edit small pieces of a code or store lists to store in various portions. Copying dif portions, etc.

The power is wild ;o.

JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro FILE_INFORMATION()
    //! runtextmacro GENERATE_JASS(&quot;Code Name&quot;)
    //! runtextmacro LEXICAL_JASS()

    //! i lexical.add([[struct Hello extends array]])
    //! i lexical.open()
        //! i lexical.add([[public static method onInit takes nothing returns nothing]])
        //! i lexical.open()
            //! i lexical.add([[//! runtextmacro WooWoo()]])
        //! i lexical.close()
        //! i lexical.add([[endmethod]])
    //! i lexical.close()
    //! i lexical.add([[endstruct]])
    //! i lexical.add([[//! textmacro WooWoo]])
    //! i lexical.open()
        //! i lexical.add([[call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, &quot;Hello World!&quot;)]])
    //! i lexical.close()
    //! i lexical.add([[//! endtextmacro]])
    
    //! i generateJASS(lexical.code())
//! endexternalblock
 

_whelp

New Member
Reaction score
54
Wait, what's the point of JASS in lua when you can just type it out on another .j file?
 

Nestharus

o-o
Reaction score
84
Let's say you want to write a system that takes JASS code and fully controls how that JASS code is entered into the system and what kind of code the system puts out to the map.

One prime example is my Spawn Framework. Another example would probably be a different implementation of SpellStruct.


If you want the most efficient and fastest code possible and you want to make it easy for the user to use, you can do this. It gets rid of the need for templates since the user can just call your functions instead =).

You can also write JASS code in response to Object Merger things.


The concept of Lexical JASS makes it so that manipulating JASS code is really easy. I'll probably add a method for copying lexical elements and returning those copies that way you can make template lexical thingies and what not.

Also, I'm changing the way how Lexical JASS works so that it does different instances ; ). The reason for this is because right now it could very easily bug o-o.

This is a WIP after all (technically alpha).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top