Initializes plugin template with Lua support

Sets up the basic project structure for a Lumenite plugin,
including CMake configuration, Lua integration, and a
sample plugin implementation.

This commit introduces the necessary files and configurations
to create a functional Lumenite plugin that can interact with
the engine via Lua scripting.

It also includes a basic plugin API header for defining
plugin metadata and export functions.
This commit is contained in:
2025-07-26 13:28:35 -05:00
parent 45cc24aa53
commit 4e017af194
7 changed files with 100 additions and 54 deletions

1
.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
lumenite_plugin

View File

@@ -1,8 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<module classpath="CMake" type="CPP_MODULE" version="4" />

View File

@@ -3,7 +3,9 @@
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="65311c3f:19834d23515:-6bbe" />
<option name="migrated" value="true" />
<option name="pristineConfig" value="false" />
<option name="userId" value="6388082f:1982fda9ebc:-7ff9" />
</MTProjectMetadataState>
</option>
</component>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

View File

@@ -5,25 +5,70 @@ project(lumenite_plugin VERSION 1.0.0 LANGUAGES C CXX)
set(PLUGIN_NAME HelloPlugin)
set(PLUGIN_VERSION 1.0.0)
file(GLOB LUA_SRC CONFIGURE_DEPENDS "vendor/lua/*.c")
# Force static C runtime (MSVC only)
if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()
add_library(${PLUGIN_NAME} SHARED
plugin.cpp
${LUA_SRC}
# Static Lua source list
set(LUA_SRC
vendor/lua/lapi.c
vendor/lua/lauxlib.c
vendor/lua/lbaselib.c
vendor/lua/lcode.c
vendor/lua/lcorolib.c
vendor/lua/lctype.c
vendor/lua/ldblib.c
vendor/lua/ldebug.c
vendor/lua/ldo.c
vendor/lua/ldump.c
vendor/lua/lfunc.c
vendor/lua/lgc.c
vendor/lua/linit.c
vendor/lua/liolib.c
vendor/lua/llex.c
vendor/lua/lmathlib.c
vendor/lua/lmem.c
vendor/lua/loadlib.c
vendor/lua/lobject.c
vendor/lua/lopcodes.c
vendor/lua/loslib.c
vendor/lua/lparser.c
vendor/lua/lstate.c
vendor/lua/lstring.c
vendor/lua/lstrlib.c
vendor/lua/ltable.c
vendor/lua/ltablib.c
vendor/lua/ltm.c
vendor/lua/lundump.c
vendor/lua/lutf8lib.c
vendor/lua/lvm.c
vendor/lua/lzio.c
)
# Build static Lua lib
add_library(lua STATIC ${LUA_SRC})
target_include_directories(lua PUBLIC vendor/lua)
target_compile_definitions(lua PRIVATE LUA_COMPAT_5_3)
# Build plugin DLL, linked statically to Lua
add_library(${PLUGIN_NAME} SHARED plugin.cpp)
target_link_libraries(${PLUGIN_NAME} PRIVATE lua)
target_include_directories(${PLUGIN_NAME} PRIVATE vendor/lua include)
# Define plugin version macros
target_compile_definitions(${PLUGIN_NAME} PRIVATE
PLUGIN_NAME="${PLUGIN_NAME}"
PLUGIN_VERSION="${PLUGIN_VERSION}"
)
# Output name like lumenite_HelloPlugin.dll
set_target_properties(${PLUGIN_NAME} PROPERTIES
OUTPUT_NAME "lumenite_${PLUGIN_NAME}"
PREFIX ""
)
if (WIN32)
target_compile_definitions(${PLUGIN_NAME} PRIVATE LUA_BUILD_AS_DLL)
# Disable CRT warnings
if (MSVC)
target_compile_definitions(${PLUGIN_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
endif ()

View File

@@ -1,10 +1,15 @@
#ifndef LUMENITE_API_H
#define LUMENITE_API_H
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include <cstdio>
// ANSI Color Macros
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
@@ -13,53 +18,42 @@
#define BOLD "\x1b[1m"
#define RESET "\x1b[0m"
// Export macro
#ifdef _WIN32
#define LUMENITE_EXPORT extern "C" __declspec(dllexport)
# define LUMENITE_EXPORT extern "C" __declspec(dllexport)
#else
#define LUMENITE_EXPORT extern "C"
# define LUMENITE_EXPORT extern "C"
#endif
// Plugin metadata struct
struct LumenitePluginMeta {
const char* name;
const char* version;
const char* engine_version;
int (*luaopen)(lua_State*);
struct LumenitePluginMeta
{
const char *name;
const char *version;
const char *engine_version;
int (*luaopen)(lua_State *);
};
// Default engine version
#ifndef LUMENITE_ENGINE_VERSION
#define LUMENITE_ENGINE_VERSION "2025.5"
# define LUMENITE_ENGINE_VERSION "2025.5"
#endif
// Stringify helpers
#define STR(X) #X
#define XSTR(X) STR(X)
#define STR(x) #x
#define XSTR(x) STR(x)
// Fallback if plugin forgot to call macro
LUMENITE_EXPORT inline const LumenitePluginMeta* lumenite_get_pmeta() {
fprintf(stderr,
WHITE "[" RED "!" WHITE "] " RESET
BOLD "Lumenite Plugin Load Error:" RESET "\n"
" This plugin is missing the required " YELLOW "LUMENITE_PLUGIN" RESET " macro.\n"
" → Call " YELLOW "LUMENITE_PLUGIN(PLUGIN_NAME, PLUGIN_VERSION)" RESET " after luaopen_plugin().\n");
return nullptr;
#define LUMENITE_PLUGIN(NAME, VERSION) \
extern "C" int luaopen_plugin(lua_State *); \
static LumenitePluginMeta __lumenite_plugin_meta = { \
NAME, VERSION, LUMENITE_ENGINE_VERSION, luaopen_plugin \
}; \
LUMENITE_EXPORT const LumenitePluginMeta *lumenite_get_pmeta() { \
return &__lumenite_plugin_meta; \
}
// Auto-register plugin metadata using defines from CMake
#define LUMENITE_PLUGIN(NAME, VERSION) \
extern "C" int luaopen_plugin(lua_State*); \
static LumenitePluginMeta __lumenite_plugin_meta = { \
NAME, VERSION, LUMENITE_ENGINE_VERSION, luaopen_plugin \
}; \
LUMENITE_EXPORT const LumenitePluginMeta* lumenite_get_pmeta() { \
return &__lumenite_plugin_meta; \
}
// Default usage
#ifdef PLUGIN_NAME
LUMENITE_PLUGIN(XSTR(PLUGIN_NAME), XSTR(PLUGIN_VERSION))
#if defined(PLUGIN_NAME) && defined(PLUGIN_VERSION)
LUMENITE_PLUGIN(XSTR(PLUGIN_NAME), XSTR(PLUGIN_VERSION))
#else
# pragma message("[Lumenite] Warning: Missing PLUGIN_NAME or PLUGIN_VERSION definitions.")
# pragma message("[Lumenite] You must call LUMENITE_PLUGIN(\"MyPlugin\", \"1.0.0\")")
#endif
#endif // LUMENITE_API_H

View File

@@ -1,5 +1,6 @@
#include "lumenite_api.h"
//
// ─────────────────────────────────────────────────────────────────────────────
//! Plugin Metadata Declaration
@@ -23,9 +24,10 @@
// local plugin = require("HelloPlugin")
// local sum = plugin.add(3, 4) -- returns 7
//
static int lua_add(lua_State* L) {
int a = luaL_checkinteger(L, 1);
int b = luaL_checkinteger(L, 2);
static int lua_add(lua_State *L)
{
const lua_Integer a = luaL_checkinteger(L, 1);
const lua_Integer b = luaL_checkinteger(L, 2);
lua_pushinteger(L, a + b);
return 1;
}
@@ -39,7 +41,8 @@ static int lua_add(lua_State* L) {
//
//* It should return a Lua table of functions, constants, or classes.
//
extern "C" int luaopen_plugin(lua_State* L) {
extern "C" int luaopen_plugin(lua_State *L)
{
lua_newtable(L);
// plugin.message = "Hello from Lumenite C++ plugin!"