| 724 | } |
| 725 | |
| 726 | bool EnableHotReloadForFile(lua_State* L, String file) { |
| 727 | // file is a vfs file so you must consult the import table |
| 728 | // to figure out what the source asset is |
| 729 | // additionally it is assumed that the top of the stack is the table that represents the loaded file |
| 730 | // it's the table that will be replaced if a hot reload occurs |
| 731 | |
| 732 | for (i64 i = 0; i < pState->pImportTable->table.tableSize; i++) { |
| 733 | HashNode<String, AssetImporter::ImportTableAsset>& node = pState->pImportTable->table.pTable[i]; |
| 734 | if (node.hash != UNUSED_HASH) { |
| 735 | if (node.value.enableAutoImport && EndsWith(file, node.value.outputPath, SlashInsensitive)) { |
| 736 | FileWatcherAddDirectory(pState->pWatcher, TakeBeforeLastSlash(node.key)); |
| 737 | pState->assetsToWatch.PushBack(node.key); |
| 738 | luaL_findtable(L, LUA_REGISTRYINDEX, "_ASSETS", 1); |
| 739 | lua_pushlstring(L, node.key.pData, node.key.length); // source asset name |
| 740 | lua_pushvalue(L, -3); // copy of the asset table |
| 741 | lua_settable(L, -3); // set asset into _ASSETS table |
| 742 | lua_pop(L, 1); // pop _ASSETS table |
| 743 | return true; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | return false; |
| 748 | } |
| 749 | }; |