DX Unified Infrastructure Management

  • 1.  LUA - Load external lua code

    Posted Apr 14, 2017 10:28 AM

    Hi 

     

    There may be situations where you want to write "big" lua scripts where you repeat many functions or metatables. For an interval script or a manual script (Dont do this on arrival, or only for 2/3 functions). 

     

    My example only take ~1millisecond to load (Very clean).

     

    external.txt with the tdump function : 

     

     

    On on my script : 

     

     

    Note ( My chunk memory is optimized for my case ). So if you want to load multiple files (like a set of metatables) you have to change the structure. 

     

    You can also return directly _a(_s(buf)) to delete this useless variable assignment.

     

    Hope this can be useful for some people ! 

     

    Best Regards,

    Thomas



  • 2.  Re: LUA - Load external lua code

    Posted Apr 14, 2017 10:40 AM

    Another note, you can pass arguments to the external lua file : 

     

    Just add arguments to the export function like this : 

    return export("hello world"); 

     

    and in the external.txt at the start : 

    return (function (msg)       local function echo()          print (msg);     end      return {         echo = echo     };  end)(...)

     

     

    msg is now equal to "hello world" when the function is called.

     

    Best Regards,

    Thomas



  • 3.  Re: LUA - Load external lua code

    Posted Apr 24, 2017 06:33 AM

    I was not aware but it's possible to use require lua file (with no extensions) into the nas directory or scripts directory. It work too !