Skip to content

Latest commit

 

History

History
82 lines (58 loc) · 2.58 KB

File metadata and controls

82 lines (58 loc) · 2.58 KB

Your first script

Summary

The smallest working mod. You write a Luau file, then run it from your Geode mod's C++ with runFile.

The example mod template already contains the matching src/main.cpp and mod/Bootstrap.luau. Follow this page when adding the same setup to an existing mod.

Step 1: write the script

Create a .luau file in your mod resources, for example Bootstrap.luau. List it in your mod.json resources. See Installation.

print("Hello from Luau")

See globals for print behavior.

Step 2: run it from C++

Include the header and call runFile with your resources directory and the file name. All public functions live in the imes::luauapi namespace.

LuauAPI exports include/LuauAPI.hpp through api.include in its mod.json.

#include <Geode/Geode.hpp>
#include <Geode/loader/ModEvent.hpp>
#include <imes.luauapi/include/LuauAPI.hpp>

using namespace geode::prelude;
namespace lua = imes::luauapi;

$on_mod(Loaded) {
    auto result = lua::runFile(Mod::get()->getResourcesDir(), "Bootstrap.luau");
    if (result.isErr()) {
        log::error("script failed: {}", result.unwrapErr());
    }
}

See Getting started for the main-thread rule. $on_mod(Loaded) already runs on the main thread, so call runFile directly there. LuauAPI owns the runtime, so you do not start it. Check status() is Ready first if you need to. If Bootstrap.luau needs functions or values from your C++ code, register them before runFile.

The rules

The file name must be a flat .luau resource name inside the resources directory you pass. See Installation for how Geode packs resource files. See modules and Limits and errors.

Using the executor

LuauAPI includes a built-in script executor. It is an ImGui window where you write Luau and run it live in the game. Turn on Enable Developer Mode under Developer Settings in LuauAPI mod settings, restart the game, then turn on Enable Script Executor. The executor toggle appears only after developer mode is on. Use it to test snippets without a build step.

Next

Related

Source

  • src/api.cpp
  • include/LuauAPI.hpp
  • src/core/Runtime.cpp