lua-astra 0.47.0

🔥 Blazingly Fast 🔥 runtime environment for Lua
---@meta

---@class Astra
Astra = {
  version = "@ASTRA_VERSION",
  --- The current running script
  current_script = "",
  --- The first script that was ran in the commandline
  main_script = "",
}

--- The current running script, use `Astra.current_script` instead
---@deprecated
CURRENT_SCRIPT = ""
--- The first script that was ran in the commandline, use `Astra.main_script` instead
---@deprecated
MAIN_SCRIPT = ""

--[[
    All of the smaller scale components that are not big enough to need their own files, are here
]]

---Pretty prints any table or value
---@param ... any
function pprint(...)
  ---@diagnostic disable-next-line: undefined-global
  astra_internal__pretty_print(...)
end

---@return string
function uuid()
  ---@diagnostic disable-next-line: undefined-global
  return astra_internal__uuid()
end

---This function is deprecated, use `clean_require` instead
---
---Invalidates imported module cache
---
---Modules are cached upon importing at Astra, you can use this
---function to remove those caches
---@param path string
---@deprecated
function invalidate_cache(path)
  ---@diagnostic disable-next-line: undefined-global
  astra_internal__invalidate_cache(path)
end

---Modules are cached upon importing at Astra, you can use this
---function to remove those caches
---@param path string
function clean_require(path)
  ---@diagnostic disable-next-line: undefined-global
  astra_internal__invalidate_cache(path)
end

---Represents an async task
---@class TaskHandler
---@field abort fun(self: TaskHandler) Aborts the running task
---@field await fun(self: TaskHandler) Waits for the task to finish

---Starts a new async task
---@param callback fun() The callback to run the content of the async task
---@return TaskHandler
function spawn_task(callback)
  ---@diagnostic disable-next-line: undefined-global
  return astra_internal__spawn_task(callback)
end

---Starts a new async task with a delay in milliseconds
---@param callback fun() The callback to run the content of the async task
---@param timeout number The delay in milliseconds
---@return TaskHandler
function spawn_timeout(callback, timeout)
  ---@diagnostic disable-next-line: undefined-global
  return astra_internal__spawn_timeout(callback, timeout)
end

---Starts a new async task that runs infinitely in a loop but with a delay in milliseconds
---@param callback fun() The callback to run the content of the async task
---@param timeout number The delay in milliseconds
---@return TaskHandler
function spawn_interval(callback, timeout)
  ---@diagnostic disable-next-line: undefined-global
  return astra_internal__spawn_interval(callback, timeout)
end

---Splits a sentence into an array given the separator
---@param input_str string The input string
---@param separator_str string The input string
---@return table array
---@nodiscard
function string.split(input_str, separator_str)
  local result_table = {}
  for word in input_str:gmatch("([^" .. separator_str .. "]+)") do
    table.insert(result_table, word)
  end
  return result_table
end

---Load your own file into env
---@param file_path string
function dotenv_load(file_path)
  ---@diagnostic disable-next-line: undefined-global
  return astra_internal__dotenv_load(file_path)
end

dotenv_load(".env")
dotenv_load(".env.production")
dotenv_load(".env.prod")
dotenv_load(".env.development")
dotenv_load(".env.dev")
dotenv_load(".env.test")
dotenv_load(".env.local")

---@param key string
function os.getenv(key)
  ---@diagnostic disable-next-line: undefined-global
  return astra_internal__getenv(key)
end

---Sets the environment variable.
---
---NOT SAFE WHEN USED IN MULTITHREADING ENVIRONMENT
---@param key string
---@param value string
function os.setenv(key, value)
  ---@diagnostic disable-next-line: undefined-global
  return astra_internal__setenv(key, value)
end