import 'reflect-metadata' ; export const luaEvents = new Map < string , { toLuaEvent : ( e : any ) => any ; } > ( ) ; const LuaFunctionPrefix = 'lua_' ; export function luaMethod ( ) { return ( target , property , descriptor ) => { const obj = target as any ; const key = String ( property ) ; if ( typeof obj . setInjectFunction === 'function' && key . startsWith ( LuaFunctionPrefix ) ) { const fn = descriptor . value ; descriptor . value = function ( ... args ) { try { return fn . apply ( this , args ) ; } catch ( e ) { console . log ( `Error exec lua-ts function ${ key }, e=${ e . message ? e . message : e }` ) ; } } ; obj . setInjectFunction ( key . substring ( LuaFunctionPrefix . length ) , descriptor . value ) ; return descriptor ; } } ; } interface LuaEventParam { description : string ; luaEventType : any ; name ? : string ; } export function luaEvent ( p ) { return target => { const c = new ( target as any ) ( ) ; c . name = target . name ; c . returnType = p ; if ( ! c . toLuaEvent ) { console . log ( 'Need to have toLuaEvent function' ) ; } luaEvents . set ( p . name ? p . name : target . name , c ) ; } ; }