Automatically reload lua code

!!! Please ensure, that your contribution or question is placed into the relevant section !!!
Questions about rolling stock, for example, do not belong in "Questions about the Forum". Following is perhaps the right area where your question will be better looked after:
General questions to EEP , Splines, rolling stock, Structures in EEP, landscape elements, Signalling system and controlling, designers, Europe-wide EEP meetings , Gossip
Your cooperation to keep the forum clear is appreciated.
In the case of pictures that are attached to the article, the source must also be stated. This also applies to your own pictures, which were taken by you. Pictures without source information will be deleted!
  • Started with lua programming where I use Notepad++ for editing the code.
    What I find very irritating is the fact that when I change the code in Notepad++ and go back to EEP the code is not automatically reloaded.

    I always have to manually reload the code, for example using the lua button and then reload script, this only working when using require() or dofile().


    So I found a way to automatically reload the code when going back to EEP which makes it much more comfortabel changing the code and testing it in EEP.


    Has somebody found a way to automatically reload the lua code? Maybey an easier way?

    EEP 16.4

    Windows 10 Education

    AMD Ryzen 7 3700XT, 32 GB RAM

    AMD Radeon RX 5600 XT 6GB

  • Hallo Feike,

    not really clear to me, what exactly you are doing. I am missing a piece. Why should something happen in EEP Script Editor, when you edit it in Notepad?


    Are you talking about editing a file in Notepad and copy the file?


    Just in case but the Script Editor has a checksum (Kudos to Goetz) and the "Anlage" is checking this checksum (or the other way around).


    So you cannot replace the "Anlage".lua file with a file written in Notepad.

    Gruß


    Paul


  • Hello Paul


    Nothing should happen in the EEP Script Editor.

    But when I change something in Notepad++ and the go back to EEP the changed script is not loaded.

    I have to click on the lua button and then click reload script to reload the changed script.

    And it is this step that I automated.

    EEP 16.4

    Windows 10 Education

    AMD Ryzen 7 3700XT, 32 GB RAM

    AMD Radeon RX 5600 XT 6GB

  • And it is this step that I automated

    Lot's of people would be grateful if you could share this. Is it done with AutoIt or so ?


    Viele Leute werden dankbar sein, wenn Sie dies teilen könnten. Wird es mit AutoIt oder so gemacht ?

    Desktop : Windows 10 Pro 64Bit - i7-4790 4.0Ghz - 32Gb RAM - Asus Geforce GTX-06G 1060 (6Gb) - Dual screen Asus VS247 24"
    Laptop : Windows 10 Home 64Bit - i7-4750HQ 3.2Ghz - 16Gb RAM - NVidia GTX960M


    Ich bin dabei seit EEP 6 und benutze jetzt EEP 17


    Free EEP-tools : Model Multiplier / Texture Multiplier / EEP window restore Tool / EEP Inventory Exporter / EEP-17+ Settings editor


    37310-banner2018-jpg

  • I will be happy to share this.

    At the moment I have at work a ransomware on a few servers.

    As a member of the ICT department I'm a bit busy...

    So it will take some time before I will be back to share the solution.

    EEP 16.4

    Windows 10 Education

    AMD Ryzen 7 3700XT, 32 GB RAM

    AMD Radeon RX 5600 XT 6GB

  • To reload the lua I need some form of communication between EEP and, for example, Notepad++.

    I am using a temporary file and read the content of this tmp file and if it contains the word 'dofile' (without quotes) the lua is reloaded and then the tmp file will be emptied.


    To do this some lua is needed which is in the file faoLibrary.lua which is placed in the lua directory of the EEP installation.
    The reload process uses the function dofile(), when using require() it won't work.


    In EEP I made two modifications: in the lua file of the layout and in the function EEPMain()


    The lua file of the layout exists of 6 lines:


    faoDirLuaLayout="f:/eep/anlagen/treintafel/"

    faoDirLuaEep="s:/eep16/lua/"

    faoTmpDoFiles={faoDirLuaLayout .. "eepmain.lua",faoDirLuaLayout .. "switch.lua"}

    faoTmpTmpFile="y:/temp/eep.tmp"

    faoTmpDelaySeconds=0


    dofile(faoDirLuaEep .. "/faoLibrary.lua")

    • Line 1
      The directory of the layout working on
    • Line 2
      The lua directory of the EEP installation
    • Line 3
      A table with all the lua files that needs to be reloaded
    • Line 4
      The path and name of the tmp file
    • Line 5
      How often will the tmp file be checked
      If this value is 0 the tmp file will be checked everytime EEPMain() is called otherwise there is a pause between the checkes with the given seconds
    • Line 6
      The faoLibray.lua is loaded
      This will initiaze the tmp file and then load the lua files that are in the table faoTmpDoFiles

    In the function EEPMain() two lines has te be added.

    I placed the function EEPMain() in the file eepmain.lua.

    Here the content of my eepmain.lua:


    clearlog()


    print("Hey let's start, EEP Version is: ", EEPVer)

    print(os.date("%H:%M:%S"))


    function EEPMain()

    faoTmpReadContent()

    faoTmpAutoReloadLua()

    return 1

    end


    The two lines starting with fao are added.


    That's all for the EEP side of things.


    Now we must change the content of the tmp file to 'dofile' when the one or more lua files are changed in Notepad++.

    This can be done using any text editor: open the tmp file anter the text dofile and save it.

    To make things easier I made a small command line tool called eeptmp

    This tool has to be started with one parameter, that is the tmp file.

    For example: eeptmp y:/temp/eep.tmp

    After the tmp file has been updated this tool will automatically switch to EEP.


    Add this command in Notepad++ to the run menu.

    And then add a shortcut to thus run option.

    In my Notepad++ I added the shortcut ctrl-shift-`: in my case this shortcut can be pressed with one hand.

    So now I change one or more lua files, save them and the press the chosen shortcut.


    Some remarks:

    • Everyting in faoLibray, variables and function, will start with fao
    • All variables and function uses for the tmp file will start with faoTmp
    • This is the best I could think of with the standard Lua that is in EEP.
      There are better solution but for that I need Lua extensions.
      Does EEP support Lua extensions?
    • The faoLibrary.lua is attached to this message
    • How do I share the file eeptmp.exe because it cannot be attached to this message.
    • If faoTmpDelaySeconds is set to 0, it will create very much disk IO.
      And for me to much disk IO on my SSD.
      Therefore I placed the tmp file on a ramdisk: there it can disk IO without a problem. For the ramdisk I use the tool imdisk
    • When there is an error message in the Event Window the the reload won't work: click on the lua button and the reload the script.
      Haven't found a solution for this. Any ideas?

    No idea if it works on another installation of EEP.

    Hopefully somebody can test it.

    On my PC it works just fine

    Files

    • faoLibrary.lua

      (1.36 kB, downloaded 113 times, last: )

    EEP 16.4

    Windows 10 Education

    AMD Ryzen 7 3700XT, 32 GB RAM

    AMD Radeon RX 5600 XT 6GB

  • Hi Feike,


    The way EEP edits, loads and saves your Lua stuff is annoying.

    One approvement indeed is to use Notepad++ as your editor.

    A second approvement is to use the following construction:


    Suppose you create a layout "Test" in the following directory:


    C:\Trend\EEP16\Resourcen\Anlagen\Test


    with the layout files:

    • Test.anl3
    • Test.lua
    • TestB.bmp
    • TestF.bmp
    • :

    In this Test.lua file you place only one line of code which will never change:


    require "Test/Mycode"


    Create a new LUA directory Test:


    C:\Trend\EEP16\LUA\Test


    Then put your code in a file Mycode.lua and save it here:


    C:\Trend\EEP16\LUA\Test\Mycode.lua


    Now you only have to do a reload of the script "Test.lua" if you change your "Mycode.lua" file.


    Good luck, Peter.

    Windows 10 Pro 64bit

    Intel i9 9900k 8 cores @ 3.6 GHz, 32GB RAM

    NVidia GeForce RTX 2080 Ti 11GB

    Started in 2017 with EEP13, now using EEP17 (LUA expert)


    Groeten, Peter Nelissen :af_1:

  • After doing some experimenting and I came up with a selfmade GBS program.

    I made a few small changes to the above mentioned faoLibrary.

    Next I made a GBS program, see attached screenshot.

    In this first attempt I can set switches and signals by typing the number and select a camera view.

    My setup is now that EEP is running on my desktop in full screen (F4) and my GBS program is running on my laptop.

    Works great togheter: full screen and the possibility to set switches and signals and change camera views.

    Now thinking what I can do more with my GBS program.

  • When needed I can share the slightly modified faoLibrary.

    The function eepmain() which I showed in message #7 above changed also slightly.


    met vriendelijke groeten


    Feike

    EEP 16.4

    Windows 10 Education

    AMD Ryzen 7 3700XT, 32 GB RAM

    AMD Radeon RX 5600 XT 6GB

    The post was edited 1 time, last by Feike ().