Skip to content

Core Module

STBrian edited this page Oct 10, 2025 · 7 revisions

The Core module contains functions that interact directly with the console or with LunaCore

Within this module you will find the following submodules:

  • Filesystem
  • Debug
  • Keyboard
  • Memory
  • System
  • Graphics

Filesystem

The Filesystem submodule contains functions related to folders and files from the sdcard or the game extdata. You can access sdcard by using sdmc:/ prefix at the start of a path, in the other hand, to access game extdata, use the prefix extdata:/

Note: If the game has not yet created the extdata, it will not work until the next game launch.

Core.Filesystem.open

Opens a file. Returns nil if the file wasn't opened with an error message. It will return a FilesystemFile object that contains methods that you can use to read or write to the file. Check FilesystemFile methods.

local optionsFile = Core.Filesystem.open("extdata:/options.txt", "r")
if optionsFile then -- Checks that optionsFile is not nil, in other words, that the file opened successfully
    --- < your code here >
else
    Core.Debug.message("Failed to open extdata:/options.txt")
end

Core.Filesystem.fileExists

Checks if the path exists and is a file

if Core.Filesystem.fileExists("sdmc:/yourfile.txt") then
    --- < your code here >
end

Core.Filesystem.directoryExists

Checks if the path exists and is a directory

if Core.Filesystem.directoryExists("sdmc:/path/to/folder") then
    --- < your code here >
end

Core.Filesystem.getDirectoryElements

If the directory exists, it will return a table that contains all elements inside that directory

local function iterateRDir(path)
    local elements = Core.Filesystem.getDirectoryElements(path)
    for index, value in ipairs(elements) do
        Core.Debug.message(path..value)
        if Core.Filesystem.directoryExists(path..value) then -- directoryExists can also be used to detect if a path is a directory
            iterateRDir(path..value.."/")
        end
    end
end

iterateRDir("extdata:/")

Core.Filesystem.createDirectory

Creates the provided directory and returns if success. It will fail if the directory already exists

if Core.Filesystem.createDirectory("sdmc:/path/to/folder") then
    --- < success >
else 
    --- < failure >
end

FilesystemFile Methods

FilesystemFile:read

Clone this wiki locally