mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-05-01 01:05:00 +00:00
fix(types): enhance type safety in callLuaFunction and loadPackageComponents functions
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import * as fengari from 'fengari-web'
|
||||
|
||||
import { fromLua } from '@/lib/lua/functions/converters/from-lua'
|
||||
import type { JsonValue } from '@/types/utility-types'
|
||||
import type { LuaState } from '@/lib/lua/functions/types'
|
||||
|
||||
const lua = fengari.lua
|
||||
|
||||
@@ -11,7 +13,7 @@ const lua = fengari.lua
|
||||
* @param functionName - Name of the function to call
|
||||
* @returns The result of the function call
|
||||
*/
|
||||
export function callLuaFunction(L: any, tableIndex: number, functionName: string): any {
|
||||
export function callLuaFunction(L: LuaState, tableIndex: number, functionName: string): JsonValue {
|
||||
// Get the function from the table
|
||||
lua.lua_getfield(L, tableIndex, fengari.to_luastring(functionName))
|
||||
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
import { getDeclarativeRenderer } from '../renderer/get-declarative-renderer'
|
||||
import type { DeclarativeComponentConfig } from '../types'
|
||||
|
||||
export function loadPackageComponents(packageContent: any) {
|
||||
interface LuaScriptConfig {
|
||||
id: string
|
||||
code: string
|
||||
parameters?: { name: string }[]
|
||||
returnType?: string
|
||||
isSandboxed?: boolean
|
||||
allowedGlobals?: string[]
|
||||
timeoutMs?: number
|
||||
}
|
||||
|
||||
interface PackageContent {
|
||||
componentConfigs?: Record<string, DeclarativeComponentConfig>
|
||||
luaScripts?: LuaScriptConfig[]
|
||||
}
|
||||
|
||||
export function loadPackageComponents(packageContent: PackageContent) {
|
||||
const renderer = getDeclarativeRenderer()
|
||||
|
||||
if (packageContent.componentConfigs) {
|
||||
@@ -11,7 +26,7 @@ export function loadPackageComponents(packageContent: any) {
|
||||
}
|
||||
|
||||
if (packageContent.luaScripts) {
|
||||
packageContent.luaScripts.forEach((script: any) => {
|
||||
packageContent.luaScripts.forEach((script: LuaScriptConfig) => {
|
||||
renderer.registerLuaScript(script.id, {
|
||||
code: script.code,
|
||||
parameters: script.parameters || [],
|
||||
|
||||
Reference in New Issue
Block a user