Jass+lua?

Nestharus

o-o
Reaction score
84
Saw somewhere Vexorian say that you could write plain LUA in JASS with //! i directive, but in his guide I read it only works with external lua files and that the //! i passes arguments into those files.

Is there any way to write plain old LUA in WE and have it run? I've been trying and nothing works ^_^. Wouldn't even know how I would print text, lol. Tried the print for printing code, but that ofc did nothing =P.
 

weaaddar

New Member
Reaction score
6
Yeah, you can do it with external block and object merger as an example. As a note, its compile time only, and you can't get the value out unless it has a readable sideeffect.

I.e. setting an ItemName you can't query the lua directly, but you can use the Jass native. You can't use Lua for jass code generation either, so you probably want to mix textmacros and lua.

something like I do in my defunct idea of DbMod here:: http://www.thehelper.net/forums/showthread.php?t=142836
 

Nestharus

o-o
Reaction score
84
er... I wouldn't be using anything inside of object merger at all...

so how would I be able to use plain lua code.. like lua functions etc, and then use macros to run the code using that lua code??

your example didn't show me anything -.-. It was pretty much using the functions in the ObjectMerger.
 

weaaddar

New Member
Reaction score
6
Object merger works because it accepts a $FileName$ you need some sort of external block that accepts an extension. The example has something interesting in it, in that I do some compile time code as I generate I built up an ability and use arrays and what not. I do some native lua operations, namely table creation, concats and multiplication.

ObjectMerger and text macros is a good idea, as you can sneak initialization stuff of data that doesn't have natives into a libraries/structs onInit method, while you generate this data for the object data.


You could try to just write plain lua use [ljass]//! i whatever[/ljass] but as I said you can't use lua to generate jass code. Maybe you can use lua to write a .j file that you can import or preload (maybe?), but unless you have a side effect like object merger does whats the point. There is no way for the Jass to communicate with it.

Lua would be a really great pre-processor for jass as then you'd have a very powerful turing complete macro system that you can use to generate C++ style templates.
 

Nestharus

o-o
Reaction score
84
Yup.. I was hoping to use it for generation of JASS code, hence the reason why I said your example didn't help at all : )
 

weaaddar

New Member
Reaction score
6
I think if you write an extension that creates a .j file that you can use lua to import that'll work. I just don't know how to do that.
 

Nestharus

o-o
Reaction score
84
It can't be external or it'd be too much work to implement -.-.

I need it to be written in WE.


Now, I could do a full add on and try to make it a standard to make it so people can write plain LUA as a preprocessing language and just put #'s in front of the lua lines, but I really don't want to go that far. Actually it wouldn't be that much of a stretch from what's here atm =), lol. Just enable print and you're set =).
 

weaaddar

New Member
Reaction score
6
Oh I mean do File I/O. Like in the lua create a text file then have a [ljass]//! import "fileYouMadeInLua.j"[/ljass] directive.

Something like::
JASS:
//! i LuaFileOpenHere("someFile.j",w+);
//! i OutToFile("function luaTest takes nothing returns nothing"..char(10).."endfunction");
//! i LuaCloseFile("someFile.j");
//! import "someFile.j"
...
call luaTest()

Of course again, I don't know lua so I can't say what the hell the commands are :p

This migth work though:: http://www.google.com/url?q=http://...zgQoAQ&usg=AFQjCNGZaKppdlSaKLCQoj3gTvqXdD7R3Q
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
So basically what you will be allowed to do ?
Everything ?

EDIT: Ofc i mean manipulate the map on compilation, like edit the script, the ability file and so one.
 

Nestharus

o-o
Reaction score
84
I've been reading Programming in Lua First Edition since yesterday : )

edit
this doesn't seem to run (according to Azlier)
Code:
do
	local f = assert(io.open("my cheese.boo", "w"))
	f:write("Hi")
	f:close()
end

We're trying to use I/O library from WE ><

Edit
Azlier got it working : D. Actually, he found out he was looking in the wrong directory, it was working entire time : p.

edit
JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! i do
        //! i local f = assert(io.open(&quot;jass\\\\test.j&quot;, &quot;w&quot;))
        //! i f:write(&quot;struct Hello extends array&quot;)
        //! i f:write(&quot;endstruct&quot;)
        //! i f:close()
    //! i end
//! endexternalblock
///! import &quot;test.j&quot;
 

Azlier

Old World Ghost
Reaction score
461
This is how to create .j files in the NewGen\jass folder. Exciting, if only //! import worked with them on the first save and not the second.

JASS:
//! i 	assert(io.output(&quot;jass\\Test.j&quot;, &quot;w&quot;))
//! i 	io.write(&quot;Cool stuff.&quot;)
 

Nestharus

o-o
Reaction score
84
Programming in Lua First Edition
The C Book

Get cracking


This would also allow you to look online and dynamically download/import models and files. It also allows you to easily look through an online repository for code and insert whatever code you are using, etc.

The applications for this are boundless.

And you should store your io in a local variable in a do block to prevent global collisions Azlier!!

ha
 

Azlier

Old World Ghost
Reaction score
461
We thought about that. You should join chat. If possible.
 

Nestharus

o-o
Reaction score
84
Er.. they can't because this is totally jasshelper..


btw, this does not work with cJASS because the team screwed up macros. They replace $ with t's... so the FILENAME is always invalid..

that kinda makes me mad..
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top