[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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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