90 lines
2.3 KiB
C
90 lines
2.3 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "error/error.h"
|
|
#include "scriptvalue.h"
|
|
#include <lua.h>
|
|
#include <lauxlib.h>
|
|
#include <lualib.h>
|
|
|
|
typedef struct scriptcontext_s {
|
|
lua_State *luaState;
|
|
} scriptcontext_t;
|
|
|
|
/**
|
|
* Initialize a script context.
|
|
*
|
|
* @param context The script context to initialize.
|
|
* @return The error return value.
|
|
*/
|
|
errorret_t scriptContextInit(scriptcontext_t *context);
|
|
|
|
/**
|
|
* Register a C function within a script context.
|
|
*
|
|
* @param context The script context to use.
|
|
* @param fnName The name of the function in Lua.
|
|
* @param function The C function to register.
|
|
*/
|
|
void scriptContextRegFunc(
|
|
scriptcontext_t *context,
|
|
const char_t *fnName,
|
|
lua_CFunction function
|
|
);
|
|
|
|
/**
|
|
* Call a Lua function within a script context.
|
|
*
|
|
* @param context The script context to use.
|
|
* @param fnName The name of the Lua function to call.
|
|
* @param args Array of args to pass to the function (or NULL for no args)
|
|
* @param argCount The number of arguments in the args array (omitable).
|
|
* @param retValue Output to store returned value (or NULL for no return value).
|
|
* @return The error return value.
|
|
*/
|
|
|
|
errorret_t scriptContextCallFunc(
|
|
scriptcontext_t *context,
|
|
const char_t *fnName,
|
|
const scriptvalue_t *args,
|
|
const int32_t argCount,
|
|
scriptvalue_t *retValue
|
|
);
|
|
|
|
/**
|
|
* Execute a script within a script context.
|
|
*
|
|
* @param context The script context to use.
|
|
* @param script The script to execute.
|
|
* @return The error return value.
|
|
*/
|
|
errorret_t scriptContextExec(scriptcontext_t *context, const char_t *script);
|
|
|
|
/**
|
|
* Execute a script from a file within a script context.
|
|
*
|
|
* @param ctx The script context to use.
|
|
* @param fname The filename of the script to execute.
|
|
* @return The error return value.
|
|
*/
|
|
errorret_t scriptContextExecFile(scriptcontext_t *ctx, const char_t *fname);
|
|
|
|
/**
|
|
* Overridden print function for Lua scripts to output to debug.
|
|
*
|
|
* @param L The Lua state.
|
|
* @return The number of return values.
|
|
*/
|
|
int32_t scriptContextPrint(lua_State *L);
|
|
|
|
/**
|
|
* Dispose of a script context.
|
|
*
|
|
* @param context The script context to dispose of.
|
|
*/
|
|
void scriptContextDispose(scriptcontext_t *context); |