Announcement

Collapse
No announcement yet.

Read text file and run as code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read text file and run as code

    Is possible to read a text file and run the content as a code?

  • #2
    Code:
    autoplay media studio > help > [B]dofile[/B]


    Comment


    • #3
      herrin many thanks

      Comment


      • #4
        local sFile = TextFile.ReadToString("myfile.lua");
        local fCode = loadstring(sFile);

        if ( type(fCode) == "function" ) then
        fCode();
        end
        https://github.com/CentauriSoldier

        Comment


        • #5
          Lua 5.1 also has loadfile, which allows for a pure-Lua solution with bytecode support. TextFile.ReadToString stops the string at the first NUL char.

          Code:
          local f, e = loadfile("myfile.lua");
          if (type(f) == "function") then
            f();
          else
            Dialog.Message("error", tostring(e), MB_OK, MB_ICONSTOP);
          end
          Bas Groothedde
          Imagine Programming :: Blog

          AMS8 Plugins
          IMXLH Compiler

          Comment


          • #6
            Originally posted by Imagine Programming View Post
            ...TextFile.ReadToString stops the string at the first NUL char.
            I didn't realize that, good catch.
            https://github.com/CentauriSoldier

            Comment

            Working...
            X