Jass+lua?

Nestharus

o-o
Reaction score
83
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
83
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
83
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
83
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
83
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
83
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
83
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 The Helper:
    Happy Friday Night!
    +1
  • V-SNES V-SNES:
    Happy Friday Night!
    +1
  • The Helper The Helper:
    Going out of a town for the weekend will be back sunday night! Hope everyone has a great weekend!
    +2
  • The Helper The Helper:
    Happy Monday!
  • Ghan Ghan:
    Monday? Speak for yourself. :p
    +2
  • The Helper The Helper:
    Happy Taco Tuesday!
    +1
  • The Helper The Helper:
    Tacos! :)
  • The Helper The Helper:
    Check out the discord for taco pictures :) You cannot put pictures in this chat
    +1
  • The Helper The Helper:
    Damn here come the bots again - 193 online but they are totally invisible to any stats - bunch of bots!'
  • C cubanismo:
    Re: Taco Tuesday, if there were some way to share edible tacos over the internet, technology would be complete.
    +2
  • The Helper The Helper:
    One can only wish!
  • tom_mai78101 tom_mai78101:
    I'm back from Taiwan
    +1
  • The Helper The Helper:
    I am reorganizing the site I know nobody will notice but I am not done quite yet but the main forums order has been changed and there is a new news category in Other News which is all the remaining headline news stuff not categorized - Headline News is just the stuff that shows on the main page now and the news archive is off the main forums page
  • The Helper The Helper:
    and the real archive lives off of headline news
  • The Helper The Helper:
    Happy Monday!
  • V-SNES V-SNES:
    Happy Saturday!
  • The Helper The Helper:
    Happy Saturday Night!

    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