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.
  • Ghan Ghan:
    Howdy
  • 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 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