Topic: Running a LUA script from F6 console

Tibor

Topic Opener
Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2013-11-04, 22:37 UTC+1.0

Hi, as a continuation of a discussion in the other thread I have very trivial question - how to run a script..

I have a text file "test.lua" with content: base=wl.Game() x=base.map.width print (x)

and I need to run it. I know about do_file() function - it is no longer supported?? and then about use(ns, script) - and this I dont know how to use. I put test.lua into ..../src/scripting directory and call it like: use(ns("aux"),script("test")) and also: use("aux","test") but neither is the right way.

Please advice... Thanks


Top Quote
SirVer

Joined: 2009-02-19, 15:18 UTC+1.0
Posts: 1440
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2013-11-05, 07:12 UTC+1.0

the function is called dofile() not do_file(), and this should work. use("aux", "test") should also work, but the script has to be in the scripting directory before you launch the game.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2013-11-05, 08:50 UTC+1.0

It works - kind of.

Dofile does not:

dofile("test.lua") 
*** Starting Lua interpretation!
*** [/var/widelands/BZR/widelands/src/scripting/scripting.h:42] cannot open test.lua: No such file or directory
*** Ending Lua interpretation!

I wonder why it refers to the source location (where BZR was downloaded) at all, but the other way works.

This was part of confusion, which "scripting" directory was expected - in source or in final location where game is installed.

HOWEVER!!!!!! it ignores changes in my test.lua file.... This is big problem, I want to play, test couple of few-lines long codes and that is impractical via F6 console and this way is not usable as well...

face-sad.png face-sad.png

=EDIT=

are there tools that can help writing those LUA files - able to check syntax - I mean more then checking brackets and so...

Edited: 2013-11-05, 09:53 UTC+1.0

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2013-11-05, 12:05 UTC+1.0

So I installed Eclipse with LDT, so far so good - I created simple lua script... but is there a way how to load definitions of your all classes? I noticed there are "Execution environment" or "User libraries" setting...


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2013-11-05, 14:27 UTC+1.0

And another answer to my own question:

Q: How can I change content of lua script and have the game recognized it...

A: I need two lua scripts, first will be kind of wrapper and will only call 'dofile("aaaa.lua")'. A change in wrapper script will not be recognized by game, but changes in aaaa.lua will be!

Yet, another question, simple 'dofile("aaaa.lua") will return no such file/directory, I have to put full path to aaaa.lua in the wrapper script. Why? Is there a "root" or a base directory which can be used for relative path?


Top Quote
SirVer

Joined: 2009-02-19, 15:18 UTC+1.0
Posts: 1440
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2013-11-05, 19:35 UTC+1.0

Eclipse?? that seems overkill for Lua, but whatever floats your boat :). I do not think that there is any way of getting all lua constructs that we have into eclipse, so that autocompletion and stuff works, sorry. You might want to look around the world of warcraft community - all of their scripting is done in Lua too, maybe they have some nifty tools.

the use() method indeed will not recognize changes in your files while running, the proxy method you describe works. dofile() looks in the current working directory for the Lua files. If you start widelands over the console you have direct control what this directory is. In Windows you can define the working directory of a program if you create a link to it imho - do not know if this is still true for modern windows, it used to be true for win 98 which was the last windows I used.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2013-11-05, 20:00 UTC+1.0

SirVer wrote:

Eclipse?? that seems overkill for Lua, but whatever floats your boat :). I do not think that there is any way of getting all lua constructs that we have into eclipse...

If it is the case, I would rather keep geany, that is my editor of choice... it should have a lua plugin... I will investigate it...

SirVer wrote:

dofile() looks in the current working directory for the Lua files. If you start widelands over the console you have direct control what this directory is.

face-smile.png funny, I did not think about this possibility...

And thanks for you patience! face-smile.png


Top Quote