- Joined
- Jul 10, 2007
- Messages
- 6,306
Outdated!!
New- http://www.thehelper.net/forums/showthread.php?t=144824
-Alpha-
Subject to Revisions
Description
Req Code
Code
Basic Implementation-
To get JASS in map-
New- http://www.thehelper.net/forums/showthread.php?t=144824
-Alpha-
Subject to Revisions
Description
Ok, been working on Lua JASS Framework ; )
This specializes in creating JASS Files from within the map to be imported into the map!
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-
lexical.element()
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 =).
So, given I work on this some more, I'd like to hopefully make this the standard for generating JASS for maps via Lua ^_-.
Req Code
JASS:
//! textmacro FILE_INFORMATION
//! i local FILE_NAME = "Insert Your Map Name Here"
//! endtextmacro
Code
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
//! 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
Basic Implementation-
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
//! runtextmacro FILE_INFORMATION()
//! runtextmacro GENERATE_JASS("Code Name")
//! runtextmacro LEXICAL_JASS()
//! endexternalblock
To get JASS in map-
JASS:
//! import "MapName.CodeName"
Last edited: