static void load_entry_named(lua_State *L, layout_entry_t *entry) { lua_getfield(L, -1, "offset"); if (lua_isnumber(L, -1)) entry->offset = lua_tointeger(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "length"); if (lua_isnumber(L, -1)) entry->length = lua_tointeger(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "type"); if (lua_isstring(L, -1)) load_type(L, entry); lua_pop(L, 1); lua_getfield(L, -1, "endian"); if (lua_isstring(L, -1)) load_endian(L, entry); lua_pop(L, 1); }
static void load_entry_numbered(lua_State *L, layout_entry_t *entry) { #if LUA_VERSION_NUM >= 502 size_t array_len = lua_rawlen(L, -1); #else size_t array_len = lua_objlen(L, -1); #endif if (array_len >= 1) entry->offset = luau_getarray_integer(L, -1, 1); if (array_len >= 2) entry->length = luau_getarray_integer(L, -1, 2); if (array_len >= 3) { luau_getarray(L, -1, 3); load_type(L, entry); lua_pop(L, 1); } if (array_len >= 4) { luau_getarray(L, -1, 4); load_endian(L, entry); lua_pop(L, 1); } }
uint STDCALL ge_load( pbuf in ) { pubyte cur, end, ptemp; uint size; pgehead phead = ( pgehead )buf_ptr( in ); // Проверка заголовка и целостности // Сравниваем с 'GE' с двумя нулями на конце if ( *( puint )phead != GE_STRING )//0x00004547 ) msg( MNotGE | MSG_EXIT ); if ( phead->crc != crc( ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF )) msg( MCrcGE | MSG_EXIT ); if ( phead->vermajor != GEVER_MAJOR || phead->verminor > GEVER_MINOR ) msg( MVerGE | MSG_EXIT ); _vm.loadmode = VMLOAD_GE; _vm.icnv = arr_count( &_vm.objtbl ) - KERNEL_COUNT; // print("icnv=%i\n", _vm.icnv ); cur = ( pubyte )phead + phead->headsize; end = ( pubyte )phead + phead->size; while ( cur < end ) { ptemp = cur + 5; // type + flag _vm.ipack = ( *( puint )( cur + 1 )) & GHCOM_PACK ? 1 : 0; size = load_bwd( &ptemp ); ptemp = cur; // print("size=%i type=%i flag = %x\n", size, *cur, *( puint )( cur + 1 ) ); switch ( *cur ) { case OVM_NONE: load_none(); break; case OVM_BYTECODE: load_bytecode( &cur, VMLOAD_GE ); break; case OVM_EXFUNC: load_exfunc( &cur, 0 ); _vm.loadmode = VMLOAD_GE; break; case OVM_TYPE: load_type( &cur ); break; case OVM_GLOBAL: load_global( &cur ); break; case OVM_DEFINE: load_define( &cur ); break; case OVM_IMPORT: load_import( &cur ); break; case OVM_RESOURCE: load_resource( &cur ); break; case OVM_ALIAS: load_alias( &cur ); break; default: msg( MUnkGE | MSG_DVAL, cur - ( pubyte )phead ); } cur = ptemp + size; } _vm.loadmode = VMLOAD_G; _vm.icnv = 0; return 1; }