declare function rawlen < T extends AnyTable > ( this , v ) ; declare function load ( this , chunk , chunkname ? , mode ? , env ? ) ; declare function loadfile ( this , filename ? , mode ? , env ? ) ; _G . unpack ??= ( table as typeof table & Record < "unpack" , typeof _G [ "unpack" ] > ) . unpack ; export const luaAssert = _G . assert ; export const luaError = _G . error ; export const luaCoroutineWrap = coroutine . wrap ; export const luaDebugTraceback = debug . traceback ; export const luaCoroutineCreate = coroutine . create ; export const luaCoroutineResume = coroutine . resume ; export const luaLenMetamethodSupported = ( ( ) => ( setmetatable ( { } , { __len : ( ) => 42 } ) as unknown [ ] ) . length === 42 ) ( ) ; export const luaRawLen = rawlen ?? function < T extends AnyTable > ( v ) : number { if ( ! luaLenMetamethodSupported ) { return ( v as unknown as unknown [ ] ) . length ; } const mt = debug . getmetatable ( v ) ; if ( ! mt || ! rawget ( mt as { __len ? : unknown ; } , "__len" ) ) { return ( v as unknown as unknown [ ] ) . length ; } else { let len = 1 ; while ( rawget ( v as Record < string , unknown > , len as unknown as string ) ) { ++ len ; } return len - 1 ; } } ; export interface Env { [ name ] : unknown ; } export function loadLuaString ( str , env ? ) { if ( setfenv !== undefined ) { const [ f , e ] = loadstring ( str , str ) ; if ( f && env ) { setfenv ( f , env ) ; } return $multi ( f as { ( this ) : LuaMultiReturn < unknown [ ] > ; } , e as undefined ) ; } else { return load ( str , str , "t" , env ) ; } } export function loadLuaFile ( filename , env ? ) { if ( setfenv !== undefined ) { const [ f , e ] = loadfile ( filename ) ; if ( f && env ) { setfenv ( f , env ) ; } return $multi ( f as { ( this ) : unknown ; } , e as undefined ) ; } else { return loadfile ( filename , "t" , env ) ; } } export function luaGetEnv ( level , thread ? ) { const info = thread && debug . getinfo ( thread , level , "f" ) || debug . getinfo ( level + 1 , "f" ) ; if ( ! info || ! info . func ) { return ; } if ( getfenv !== undefined ) { return getfenv ( info . func ) as Env | undefined ; } else { let i = 1 ; while ( true ) { const [ name , value ] = debug . getupvalue ( info . func , i ) ; if ( ! name ) { break ; } if ( name === "_ENV" ) { return value as Env ; } ++ i ; } } }