HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[LUA]Ideas on making import of jass script by lua?

07-11-2010, 10:15 AM#1
Nestharus
So... any ideas on how to get this integer I'm making in the Lua script into the JASS without having to do //! import?

This is the code
Collapse JASS:
//! textmacro FILE_NAME
    //! i FILE_NAME = "your file name"
//! endtextmacro

//! textmacro OBJECT_CREATOR
    //! i lastCreatedObject = string.char(1, 1, 1, 0)
    //! i function IncObject(s)
    //! i       local i = 5
    //! i       repeat 
    //! i           i = i - 1
    //! i           s = string.sub(s, 1, i-1) .. string.char(string.byte(s, i)+1) .. string.sub(s, i+1)
    //! i       until (string.byte(s, i) < 127 or i == 1)
    //! i       if (string.byte(s, i) == 127) then
    //! i           return nil
    //! i       end
    //! i       return s
    //! i end
    
    //! i function ConvertObjectToInteger(object)
    //! i   return ((string.byte(object, 1)*128+string.byte(object, 2))*128+string.byte(object, 3))*128+string.byte(object, 4)
    //! i end
    
    //! i function WriteObject(object, objectName)
    //! i   local f = io.open("jass\\objectData." .. FILE_NAME .. "." .. objectName, "w+")
    //! i   f:write("globals\n\tconstant integer " .. string.upper(objectName) .. "=" .. ConvertObjectToInteger(object) .."\nendglobals")
    //! i   f:close()
    //! i end
    
    //! i function GetObject(objectName)
                //1 0 0 0 = 2097152
                //SOH NUL NUL NUL
                //start one below so 0 can be used
    //! i       local f = io.open("jass\\objectDataLua." .. FILE_NAME .. "." .. objectName, "r")
    //! i       local createdObject
    //! i       if (f == nil) then
    //! i           createdObject = IncObject(lastCreatedObject)
    //! i           local t = { "units", "items", "destructables", "doodads", "abilities", "buffs", "upgrades" }
    //! i           local i = 0
    //! i           local b = 7
    //! i           local e = true
    //! i           repeat
    //! i               i = i + 1
    //! i               if (i > 7) then
    //! i                   i = 1
    //! i               end
    //! i               setobjecttype(t[i])
    //! i               e = false
    //! i               while (objectexists(createdObject)) do
    //! i                   if (not e) then
    //! i                       e = true
    //! i                       b = b + 1
    //! i                       if (b > 7) then
    //! i                           b = 1
    //! i                       end
    //! i                   end
    //! i                   createdObject = IncObject(createdObject)
    //! i                   if (createdObject == nil) then
    //! i                       return nil
    //! i                   end
    //! i               end
    //! i           until (i == b and not e)
    //! i           f = io.open("jass\\objectDataLua." .. FILE_NAME .. "." .. objectName, "w")
    //! i           f:write(createdObject)
    //! i           f:close()
    //! i           WriteObject(createdObject, objectName)
    //! i       else
    //! i           createdObject = f:read()
    //! i           f:close()
    //! i       end
    //! i       return createdObject
    //! i   end
//! endtextmacro

And this is a script using it
Collapse JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro FILE_NAME()
    //! runtextmacro OBJECT_CREATOR()
    //! i local object = GetObject("MY_OBJECT")
    
    //! i setobjecttype("abilities")
    //! i createobject("Adef", object)
    //! i makechange(current, "anam", "Unit Indexing")
    //! i makechange(current, "ansf", "(Unit Indexing")
    //! i makechange(current, "aart", "")
    //! i makechange(current, "arac", 0)
//! endexternalblock

I'd like to be able to somehow import the file I'm making up above rather than doing this-
//! import "objectData.your file name.MY_OBJECT"
Any thoughts? : D

I think this would be a ridiculously useful script if I could get the integer into JASS : P.