NYSL
NYSL
#module #defcfunc findUnusedModuleIndex array modules, \ local index index = 0 foreach modules if cnt != index : break index++ loop return index #global // 以下テストコード、#if 1にして動作 #if 0 #module test index, var #modinit int p_val, \ local l_index mref l_index, 2 var = p_val index = l_index mes strf("CREATED #%d (%d)", index, var) return #modterm mes strf("DELETED #%d (%d)", index, var) return #global newmod m, test, 0 newmod m, test, 1 newmod m, test, 2 newmod m, test, 3 delmod m(1) newmod m, test, 4 newmod m, test, 5 newmod m, test, 6 mes strf("VACANT: #%d", findUnusedModuleIndex(m)) delmod m(4) mes strf("VACANT: #%d", findUnusedModuleIndex(m)) delmod m(2) mes strf("VACANT: #%d", findUnusedModuleIndex(m)) newmod m, test, 7 mes strf("VACANT: #%d", findUnusedModuleIndex(m)) newmod m, test, 8 mes strf("VACANT: #%d", findUnusedModuleIndex(m)) newmod m, test, 9 mes strf("VACANT: #%d", findUnusedModuleIndex(m)) #endif