SerpentLua

YellowCat98

SerpentLua

[Image: Mod Version] [Image: Downloads] [Image: GD Version] [Image: Geode Version]

  • A Geode mod for creating scripts in the Lua language.

  • View the about.md file within this repository for more information.

Table of Contents

Setup

  • Plugins use a global dependency lua.dll. Plugins will not load if this file does not exist.
  1. Open Geometry Dash and press the SerpentLua button. [Image: Visual Step 1]
  2. Press the settings button at the bottom. [Image: Visual Step 2]
  3. Press the config button at the bottom. [Image: Visual Step 3]
  4. Enter the plugin_global_deps folder. [Image: Visual Step 4]
  5. Install lua.dll there.
  6. lua.dll can be found here
  • (or just the release of whatever version of SerpentLua you have.)

Scripts

Creating your first script

  • Simply create a .lua file with the ID of your script. (e.g.: author.script_name.lua (this is the preferred naming format.))
  • At the first few lines, that is where we insert our metadata.
  • In order for them to not interfere with the Lua interpreter, they are in the form of comments.
  • Example metadata:
--@name ScriptName
--@developer Author
--@id author.script_name
--@version 1.0.0
--@serpent-version 1.0.2
--@plugins yellowcat98.plugintest@1.0.0 serpentlua.std@1.0.0
  • name: The name of the script.

  • developer: The developer of the script.

  • id: internal ID SerpentLua will use to identify this script. (note!!! Scripts will not load if their filename doesn't correspond with their ID!)

  • version: The version of the script. (Note that this isn't really used anywhere, but it's still important to increment it when necessary)

  • serpent-version: The version of SerpentLua that the script targets.

  • plugins: The plugins the script relies on. They are separated by spaces. The version after the @ is version of the plugin the scripts target. For example serpentlua.std@1.0.0 means that the script uses the serpentlua.std plugin while targeting version v1.0.0. For backwards compatibility purposes with older scripts, you can still not specify any version (--@plugins serpentlua.std or --@plugins serpentlua.std@*) and SerpentLua will just ignore the version and the script will load regardless of what plugin version you have installed. It is heavily recommended that you specify a target version. Specifying a target version will help prevent scripts from erroring when you update a plugin. Support for this capability will be removed in SerpentLua v2.0.0.

  • nostd (Optional!): Whether to import the Lua standard library or not. This option defaults to true when not provided. (I see no reason why you'd want to use this. Maybe if you're looking to maximize your sudo apt install opsec and post it on TikTok)

  • The first 7 lines must only contain metadata. SerpentLua rejects any script where the 1st-7th lines aren't metadata.

  • Error examples:

--@name hihi
if (this isnt metadata vro!) sudo rm -rf / -- Deleting the french language pack
--@jokes-to-repeat-until-unfunny 67
  • This will throw:
    • Syntax error.
    • Unknown key jokes-to-repeat-until-unfunny
    • Missing keys id, developer, version, serpent-version.

Script examples worth looking at

  • Basic Example: Example for the SerpentLua plugin's most basic functions.

  • Playground Example: Basic example for the playground module in the standard SerpentLua plugin. A module that gives sandboxes access to a directory for each plugin.

  • Modify Example: Basic example for the Modify plugin.

  • Plugin Test Example: Basic example for the Plugin examples in plugin_examples/yellowcat98.plugintest.

  • UI Example: Basic example for the UI module in the standard SerpentLua plugin. A module which allows writing basic UI code. (Though it requires that you use a Plugin like Modify to execute code at the init of any CCLayer.)

Plugins

  • Note: this is rather advanced. If you're looking just to create scripts, skip this.

Native plugins

Creating your first native plugin

  • This will only include how plugins are written. View this for compilation.
  1. Get lua.lib from whatever release of SerpentLua you have installed. As well as the Lua C API version 5.4.6. (This step was added last and i just wasnt feeling like making it step 1 and incrementing the other steps lol)
  2. Create a plugin.slm file inside the root of the project. Inside it, write your plugin metadata. Plugin metadata is written the exact same as Script metadata with the exception of removing the --@nostd and --@plugins keys.
  3. Create a serpentlua.rc file containing the following: SERPENTLUA_METADATA RCDATA "plugin.slm"
  4. Create your main.cpp source file.
  5. Include the Lua C API.
  6. Declare the struct __metadata:
struct __metadata {
   const char* name;
   const char* developer;
   const char* id;
   const char* version;
   const char* serpentVersion;
 const char** plugins; // note! `plugins` is intended for scripts.
};
  1. Declare the struct SerpentLuaAPI:
struct SerpentLuaAPI {
   void (*log)(__metadata, const char*, const char*); // Basic logging function for plugins.
 __metadata (*get_script)(lua_State*); // Basic function for retrieving scripts through state.
   __metadata metadata; // Allows access to your plugin's metadata.
   HMODULE handle; // Your Plugin's HMODULE.
};
  1. Declare the static variable of type SerpentLuaAPI (must be of any name, example: static SerpentLuaAPI api;)
  2. Declare initNativeAPI
// Important! must be exported with `extern "C"` as SerpentLua will call it!
extern "C" __declspec(dllexport) void initNativeAPI(SerpentLuaAPI TheCoolAPI) {
   api = TheCoolAPI; // `api` being the static variable you declared the previous step.
}
  1. Declare your entry function with the signature extern "C" __declspec(dllexport) void entry(lua_State* L);. lua_State* L being the Lua interpreter of whatever script is using your plugin.
  2. Inside your entry function, create a table, this table is where you store everything about your plugin.
  3. Make sure to insert your table inside the serpentlua_modules table in order to expose it to scripts.
  4. Compile it using this example.
  • If you link any dynamic libraries to your plugin, insert them in the {config_dir}/plugin_deps/plugin_filename/ folder.

    • plugin_filename: The name of your .slp file with the .slp extension omitted.
    • config_dir: The config directory of SerpentLua, located at {gd_dir}/geode/config/yellowcat98.serpentlua/
  • You can use any Lua wrapper you want, as this is just a DLL that links the Lua C API.

Native plugin example worth looking at

PluginTest: A basic plugin example. Exposes a the_Function and a coolVar variable to Lua.

Non-native plugins

Creating your first non-native plugin with the SerpentLua API

  • Note: Prior Geode SDK knowledge is highly recommended.
  1. Add yellowcat98.serpentlua as a dependency in your mod.json.
  2. Enable early-load in your mod.json. SerpentLua waits for plugins to load, not enabling early-load will cause scripts to load too late.
  3. Include ``
  4. Define your entry function. This function is the same as entry in native plugins.
  1. Inside your $on_mod(Loaded) or $execute, create your metadata.
    auto metadata = SerpentLua::PluginMetadata::createFromMod(Mod::get());
    // You can use PluginMetadata::create, which instead of taking a `Mod*` argument, it takes a `std::map` that contains your metadata keys. Though there are no advantages over `PluginMetadata::createFromMod`.
    // PluginMetadata::createFromMod also makes your Plugin automatically use whatever SerpentLua version you have installed.
    if (!metadata) /* Handle Error. */; // Optional, `metadata` is most unlikely to be nullptr.
    // The metadata keys aren't constant, you can modify them.
   // Though if you're modifying the version (for example, separating the plugin's version from your mod's version.), It is recommended to make it have a leading V. (doesn't make any difference, though it looks weird in the plugins list.)
  1. Create your Plugin*.
    auto res = SerpentLua::Plugin::create(metadata, myEntryFunction); // returns a geode::Result.
    if (res.isErr()) /* Handle error. */;

    auto plugin = res.unwrap();
    plugin->setPlugin(); // Makes the plugin visible to SerpentLua's Runtime manager.
  1. Remove your Mod ID from the SerpentLua::globals::pluginsYetToLoad vector.
    SerpentLua::globals::pluginsYetToLoad.erase(std::remove(SerpentLua::globals::pluginsYetToLoad.begin(), SerpentLua::globals::pluginsYetToLoad.end(), Mod::get()->getID()), SerpentLua::globals::pluginsYetToLoad.end());
   // This operation must run regardless of whether the plugin failed to load or not. If not removed, scripts will not load at all.
  1. Compile and run your plugin!

You may view the SerpentLua.hpp header for all exported classes and extra notes.

Non-native plugin example worth looking at

Non-native Plugintest: This pretty much the same thing as PluginTest.

Changelog

1.7.0

  • Script Metadata: Reorganize code.
  • Script Metadata: New syntax for plugins key that describes what version your plugin targets. (read the README in the GitHub repository for details)
  • Internal: Fix Semantic Versioning comparing issue. (If SL v1.8.0 ever gets released, scripts written for it won't work on v1.7.0)
  • Error logging: Clearer errors (that you probably won't see unless you have two bits of RAM)

1.6.0

  • SL Plugin v1.4.0: Add new fmt table.
  • SL Plugin v1.4.0: Reorganized code.

1.5.0

  • SL Plugin v1.3.0: Add new Notification node type.

1.4.0

  • Internal: Reorganize code.
  • UI: Add a "never show again" option in the lua.dll popup.
  • UI: Added new select UI for plugins and scripts.
  • UI: Removed plugin/script button in scripts/plugins UI.
  • UI: Unnoticeably faster plugin/script lookup.
  • Settings: New setting for the plugin index server URL and a setting to authenticate with Argon on startup.
  • Plugins: Installs plugin via ID.
  • Server: UI Utilities for SL Index Staff and SL Plugin Developers.
  • Script termination: Log error properly (how did it take me this long to find this)
  • SL Plugin v1.2.1: Fixed issue with createFromCCNode not allowing calling non-Node exclusive methods when type is provided.
  • Error handling: Made lua panic popup more detailed.
  • Native Plugins: Add deprecation warning for dynamic libraries.
  • Metadata: Fixed description grammar and removed offline tag.
  • Minecraft: Removed Herobrine.

Dev note #1: "I hate layouts"-me

1.3.0

  • SL Plugin v1.2.0: Add new Alert node type.

1.2.1

  • SL Plugin v1.1.1: Basic code improvements.
  • UI: Allow multiple scripts/plugins of the same name to appear in the UI.

1.2.0

  • SL Plugin v1.1.0: Added new enums table.
  • SL Plugin v1.1.0: Added basic UI utilities.
  • Error handling: Show system-level alert on lua panic (used to previously print error and exit immediately)

1.1.0

  • API: Expose ScriptMetadata::getScriptByState.
  • API: Expose ScriptMetadata::getScriptByID.
  • UI: Alphabetically sort scripts and plugins by name. (serpentlua std is always on top btw)

1.0.2

  • Internal: Compare versions while taking Semantic Versioning into account.
  • Script/Plugin metadata: Allow leading v in version.
  • Script/Plugin metadata: Error check version.
  • UI: Always have a leading v in version regardless of whether the version has one or not.

1.0.1

  • Internal: Properly handle error for createDirectory functions.

1.0.0

  • Internal: use Geode's pathToString utility and remove useless .string() calls.

1.0.0-alpha.2

  • UI: Make missing lua.dll popup better.
  • UI: Plugins that were never used show up in Plugins list.
  • UI: Add plugin indicator.
  • UI: Add delete script/plugin buttons.
  • UI: Add restart required indicator.
  • API: Add native key to PluginMetadata.
  • API: Add path key to PluginMetadata.
  • Plugin: Separate serpentlua.std plugin version from SerpentLua version.

1.0.0-alpha.1

  • Initial release

Original Site made by HJfod. Geode 2 parody-ish by MeFinity.

Geode-SDK is the property of the Geode Team.


This website (Geode 2, Codename Malachite) is not affiliated with the Geode Team in any way shape or form.