fix(types): enhance type safety in callLuaFunction and loadPackageComponents functions

This commit is contained in:
2025-12-30 00:48:08 +00:00
parent 8f42c03697
commit d818a93c0f
2 changed files with 20 additions and 3 deletions

View File

@@ -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))

View File

@@ -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 || [],