System Lua_file_header

Nestharus

o-o
Reaction score
84
Quickstart Guide to Lua Framework

Lua Tutorial w/ Lua Framework

JASS:

//Writes map header to map (run once, but multiple times won't hurt)
//------------------------------------------------------------------------
    //function initmap()
    
    //comment after initialization
    ///*
    //! externalblock extension=lua FileExporter $FILENAME$
        //! runtextmacro LUA_FILE_HEADER()
        //! i initmap()
    //! endexternalblock
    //*/

    //uncomment after initialization
    ///! import "luajass.FILE_NAME.j"
//------------------------------------------------------------------------


//import and run lua script to current script (all do same thing)
//------------------------
    //function dofile(name)
    //function require(name)
    //function loadfile(name)

//lua scripts are shared across all maps
//jass scripts are local to a map

//returns code inside of file
//------------------------
    //function readlua(name)
    //function readjass(name)

//writes code to file
//------------------------
    //function writelua(name, code)
    //function writejass(name, code)

//deletes file
//------------------------
    //function deletelua(name)
    //function deletejass(name)

//! textmacro LUA_FILE_HEADER
    //! i do
        //replace "FILE_NAME" with the name of the map
        //must be valid directory name
        //! i local FILENAME = "FILE_NAME"
        
        //! i function getfilename() 
            //! i return FILENAME 
        //! i end
        
        //Initialization
        ///////////////////////////////////////////////////////////////////////
        //! i local PATH_LUA_p = "grimext\\luadir"
        //! i local PATH_JASS_p = PATH_LUA_p .. "\\" .. FILENAME .. "_dir"
        
        //! i local PATH_LUA = PATH_LUA_p .. "\\"
        //! i local PATH_JASS = PATH_JASS_p .. "\\"
        //! i local JASS_HUB = "jass\\luajass." .. FILENAME .. ".j"
        //! i function initmap()
            //! i os.execute("if not exist " .. PATH_LUA .. " (mkdir " .. PATH_LUA .. ")")
            //! i os.execute("if not exist " .. PATH_JASS .. " (mkdir " .. PATH_JASS .. ")")
            //! i local file = io.open(JASS_HUB, "r")
            //! i if (file == nil) then
                //! i file = io.open(JASS_HUB, "w")
                //! i file:write("")
                //! i file:close()
            //! i else
                //! i file:close()
            //! i end
            
            //! i os.execute("if not exist grimext\\luadir\\" .. FILENAME .. "_dir (mkdir grimext\\luadir\\" .. FILENAME .. "_dir)")
        //! i end
        ///////////////////////////////////////////////////////////////////////
        
        //! i local olddofile = dofile
        //! i local oldrequire = require
        //! i local oldloadfile = loadfile
        //! i function dofile(name)
            //! i oldrequire("luadir\\" .. name)
        //! i end
        //! i function require(name)
            //! i dofile(name)
        //! i end
        //! i function loadfile(name)
            //! i dofile(name)
        //! i end
        
        //! i local function getluapath(name)
            //! i return (PATH_LUA .. name .. ".lua")
        //! i end
        //! i local function getjasspath(name)
            //! i return (PATH_JASS .. name .. ".luajass.j")
        //! i end
        //! i local function getjassimport(name)
            //! i return ("\/\/! import \"..\\" .. getjasspath(name) .. "\"")
        //! i end
        
        //! i local function del(name)
            //! i os.remove(name)
        //! i end
        //! i local function read(path)
            //! i local file = io.open(path, "r")
            //! i code = nil
            //! i if (file ~= nil) then
                //! i code = file:read("*all")
                //! i file:close()
            //! i end
            //! i return code
        //! i end
        //! i local function write(path, code)
            //! i file = io.open(path, "w")
            //! i file:write(code)
            //! i file:close()
        //! i end
        //! i local function import(name)
            //! i local code = read(JASS_HUB)
            //! i local line = getjassimport(name) .. "\n"
            //! i local s,k = code:find(line)
            //! i if (s == nil) then
                //! i write(JASS_HUB, code .. line)
            //! i end
        //! i end
        
        //! i function readlua(name)
            //! i return read(getluapath(name))
        //! i end
        //! i function writelua(name, code)
            //! i write(getluapath(name), code)
        //! i end
        //! i function readjass(name)
            //! i return read(getjasspath(name))
        //! i end
        //! i function writejass(name, code)
            //! i write(getjasspath(name), code)
            //! i import(name)
        //! i end
        //! i function deletelua(name)
            //! i del(getluapath(name))
        //! i end
        //! i function deletejass(name)
            //! i del(getjasspath(name))
            //! i local line = getjassimport(name) .. "\n"
            //! i local code = read(JASS_HUB)
            //! i local s,k = code:find(line)
            //! i if (s ~= nil) then
                //! i write(JASS_HUB, code:sub(1,s-1) .. code:sub(k+1))
            //! i end
        //! i end
    //! i end
//! endtextmacro


Demo
JASS:

//! externalblock extension=lua FileExporter $FILENAME$
    //run the header first
    //! runtextmacro LUA_FILE_HEADER()
    
    //writing an lua script to a follow
    //! i writelua("MyScript", [[
        //! i function Hello() 
            //! i logf("hi") 
        //! i end
    //! i ]])
    
    //using the lua script just written
    //! i dofile("MyScript")
    
    //calling a function inside of written lua script
    //! i Hello()
    
    //writing 3 jass scripts that are imported into the map automatically
    //-----------------------------------------------------------
        //! i writejass("MyScript", [[
            //! i struct Tester1 extends array
                //! i private static method onInit takes nothing returns nothing
                    //! i call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "hello world")
                //! i endmethod
            //! i endstruct
        //! i ]])
        
        //! i writejass("MyScript2", [[
            //! i struct Tester2 extends array
                //! i private static method onInit takes nothing returns nothing
                    //! i call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "hello world")
                //! i endmethod
            //! i endstruct
        //! i ]])
        
        //! i writejass("MyScript3", [[
            //! i struct Tester3 extends array
                //! i private static method onInit takes nothing returns nothing
                    //! i call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "hello world")
                //! i endmethod
            //! i endstruct
        //! i ]])
    //-----------------------------------------------------------
    
    //delete the second jass script
    //! i deletejass("MyScript2")
    
    //write jass script 1 and lua script to grimext logs
    //! i logf(readjass("MyScript"))
    //! i logf(readlua("MyScript"))
    
    //clear out so that you don't have to delete this demo from your directory : D
    //! i deletelua("MyScript")
    //! i deletejass("MyScript")
    //! i deletejass("MyScript3")
//! endexternalblock


Lua installation script template

http://www.hiveworkshop.com/forums/submissions-414/snippet-lua_file_header-186775/
JASS:

//MyScript v1.0.0.0
//! externalblock extension=lua FileExporter $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i writelua("MyScript", [[
    //////////////////////////////////////////////////////////////////
    //code



    //end code
    //////////////////////////////////////////////////////////////////
    //! i ]])
//! endexternalblock

 

Nestharus

o-o
Reaction score
84
Added a little mini tutorial on the top that talks about how to install lua scripts, how to install object generating scripts, how to install JASS scripts, and how to install LUA_FILE_HEADER.
 

dudeim

New Member
Reaction score
22
Ok I got one question why would I write jass using this lua thingy instead of writing normal jass?
 

Nestharus

o-o
Reaction score
84
There is an example in LUA_GET_VAR_OBJECT =).
JASS:

    //! i function updateobjects()
        //! i writejass(filename, "globals" .. vars2 .. "\nendglobals")
        //! i if (varsdata == "") then
            //! i varsdata = newvars
        //! i elseif (newvars ~= "") then
            //! i varsdata = varsdata .. "," .. newvars
        //! i end
        //! i newvars = ""
        //! i writelua(filename_lua, "return {" .. varsdata .. "}")
    //! i end


Here is also an example from AdvDamageEvent
JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    
    //! i dofile("DummyPhysicalAbility")
    
    //! i local object = getdummyphysicalability("ADV_DAMAGE_EVENT", 1, false)
    
    //! i writejass("AdvDamageEvent_GLOBALS",
        //! i [[//! textmacro ADV_DAMAGE_EVENT_EXT_GLOB_1
            //! i globals
                //! i private constant integer DUMMY_ABILITY=']] .. object.ability .. [['
                //! i private constant integer DUMMY_ABILITY_2=']] .. object.ability2 .. [['
                //! i private constant integer DUMMY_BUFF=']] .. object.buffs[1] .. [['
            //! i endglobals
        //! i //! endtextmacro]])
        
    //! i local saveBuff = getvarobject("AIlf", "abilities", "ADV_DAMAGE_EVENT_SAVE_UNIT_ABILITY", true)
    //! i createobject("AIlf", saveBuff)
    //! i makechange(current, "Ilif", "1", "500000")
    //! i makechange(current, "ahdu", "1", "1")
    //! i makechange(current, "adur", "1", "1")
    
    //! i local playerDamage = getvarobject("AIlf", "abilities", "ADV_DAMAGE_EVENT_SAVE_UNIT_ABILITY", true)
    
    //! i updateobjects()
//! endexternalblock
 

Nestharus

o-o
Reaction score
84
Yup.

LUA_GET_VAR_OBJECT generates dynamic ids that have to be accessed via variables because there is no way to know the id. I mean, you could generate JASS script to use the id directly, but then the JASS would be annoying to write ;P.

So LUA_GET_VAR_OBJECT creates a globals block of variables with the dynamic ids in them, which ofc requires the use of writejass ;D.
 
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