-- This Lua script will take projects in the form of folders and load each file to winols and set the data specified into the user info boxes within winols)
-- Designed by Dermot Kirk @ Protune For Hex-Portal.com
-- To Purchase Contact Me Directly
-- Not To Be Sold By Individuals! 
-- No Future Revisions Provided Without Purchase Proof!
-- Contact: www.protune.online or [email protected]
-- Default Load Directory = C:/WinolsProjects
-- Default Move Directory = C:/WinolsProjects/LoadedWinolsProjects
-- Default Original File Selector Text = "Original" or "Ori" - add either to your ori file names 
-- Place all "mod" files & .TXT with the name set to your preferred input in the "User1" box)

local directory = "C:/WinolsProjects"

-- Set the directory for saved projects to be moved to
local completedDirectory = "C:/WinolsProjects/LoadedWinolsProjects"

-- repeats the script until no files remain to load 
repeat
  -- Get a list of the directory tree
  local folders = winols.getFolders(directory)

  -- Check if any folders are found
  if #folders == 0 then
    break  -- No folders found, exit the loop
  end

  -- This will loop through each folder
  for _, folder in ipairs(folders) do
    -- Gets a list of all the files inside the folder
    local files = winols.getFiles(folder)
  
    -- Check if there is an original file
    local originalFile = nil
    for _, file in ipairs(files) do
      if string.find(file, "ORI") or string.find(file, "Original") then
        originalFile = file
        break
      end
    end
  
    -- if there is no original file in the folder, prompt the user to select one manually
    if not originalFile then
      originalFile = winols.openFileDialog(folder)
    end
  
    -- loads the original file
    winols.loadFile(originalFile)
  
    -- adds the other files in the folder as modified versions
    for _, file in ipairs(files) do
      if file ~= originalFile then
        winols.addModifiedVersion(file)
      end
    end
  
    -- Checking if there is a .txt format file in the folder
    local txtFile = nil
    for _, file in ipairs(files) do
      if string.find(file, ".txt") then
        txtFile = file
        break
      end
    end
  
    -- if there is a .txt file, add the filename to the "User 1" project information box for Damos name
    if txtFile then
      winols.setProjectInfo("User 1", txtFile)
    else
      -- if there is no .txt file in the folder, prompt the user to enter the Damos manually
      local userInput = winols.inputDialog("Please enter Damos information for The User 1 Box")
      winols.setProjectInfo("User 1", userInput)
    end
  
    -- Adds the project size to the "User 2" project info box
    local projectSize = winols.getProjectSize()
    winols.setProjectInfo("User 2", projectSize)
  
    -- Checks if there is only one .bin file in the folder
    local binFiles = 0
    for _, file in ipairs(files) do
      if string.find(file, ".bin") then
        binFiles = binFiles + 1
      end
    end
  
    -- Checks if there is only one .bin file in the folder. If so, prompt the user to save the project as original without any modified files
    if binFiles == 1 then
      local userInput = winols.inputDialog("Do you want to save the project without any additional file versions?")
      if userInput == "Yes" then
        winols.saveProject()
      end
    else
      -- Otherwise, continue to save the project
      winols.saveProject()
    end
  
    -- Checks if the project saved successfully and if it has, move the project folder to the completed directory
    if winols.getProjectSaved() then
      winols.moveFolder(folder, completedDirectory)
    end
  end
until true
 

Lua online compiler

Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.

Taking inputs (stdin)

OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.

name = io.read("*a")
print ("Hello ", name)

About Lua

Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.

Syntax help

Variables

  • By default all the variables declared are global variables
  • If the variables are explicitly mentioned as local then they are local variables.
  • Lua is a dynamically typed language and hence only the values will have types not the variables.

Examples

-- global variables
a = 10

-- local variables

local x = 30
Value TypeDescription
numberRepresents numbers
stringRepresents text
nilDifferentiates values whether it has data or not
booleanValue can be either true or false
functionRepresents a sub-routine
userdataRepresents arbitary C data
threadRepresents independent threads of execution.
tableCan hold any value except nil

Loops

1. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition)
do
--code
end

2. Repeat-Until:

Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.

repeat
   --code
until( condition )

3. For:

For loop is used to iterate a set of statements based on a condition.

for init,max/min value, increment
do
   --code
end

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.

optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end