// this script was compiled with wurst 1.8.1.0-jenkins-Wurst-1366 globals integer array test_b integer array Blub_nextFree integer Blub_firstFree=0 integer Blub_maxIndex=0 integer array Blub_typeId integer array Blub_x endglobals native testFail takes string msg returns nothing native testSuccess takes nothing returns nothing function initGlobals takes nothing returns nothing endfunction function Blub_onDestroy takes integer this returns nothing endfunction function error takes string msg returns nothing call BJDebugMsg(msg + "\n" + "") endfunction function dealloc_Blub takes integer obj returns nothing if Blub_typeId[obj] == 0 then call error("Double free: object of type Blub") else set Blub_nextFree[Blub_firstFree] = obj set Blub_firstFree = Blub_firstFree + 1 set Blub_typeId[obj] = 0 endif endfunction function destroyBlub takes integer this returns nothing call Blub_onDestroy(this) call dealloc_Blub(this) endfunction function dispatch_Blub_destroyBlub takes integer this returns nothing if Blub_typeId[this] == 0 then if this == 0 then call error("Nullpointer exception when calling Blub.Blub") else call error("Called Blub.Blub on invalid object.") endif endif call destroyBlub(this) endfunction function alloc_Blub takes nothing returns integer local integer this if Blub_firstFree == 0 then if Blub_maxIndex < 32768 then set Blub_maxIndex = Blub_maxIndex + 1 set this = Blub_maxIndex set Blub_typeId[this] = 1 else call error("Out of memory: Could not create Blub.") set this = 0 endif else set Blub_firstFree = Blub_firstFree - 1 set this = Blub_nextFree[Blub_firstFree] set Blub_typeId[this] = 1 endif return this endfunction function Blub_init takes integer this returns nothing endfunction function construct_Blub takes integer this, integer x returns nothing call Blub_init(this) set Blub_x[this] = x endfunction function new_Blub takes integer x returns integer local integer this = alloc_Blub() call construct_Blub(this, x) return this endfunction function init_test takes nothing returns nothing local integer i set test_b[0] = new_Blub(0) set test_b[1] = new_Blub(1) set test_b[2] = new_Blub(2) set test_b[3] = new_Blub(3) set test_b[4] = new_Blub(4) set test_b[5] = new_Blub(5) set test_b[6] = new_Blub(6) set test_b[7] = new_Blub(7) call dispatch_Blub_destroyBlub(test_b[0]) call dispatch_Blub_destroyBlub(test_b[6]) call dispatch_Blub_destroyBlub(test_b[2]) call dispatch_Blub_destroyBlub(test_b[4]) set test_b[8] = new_Blub(8) set test_b[9] = new_Blub(9) set i = 0 loop exitwhen i >= 10 if ModuloInteger(i, 2) == 1 and Blub_x[test_b[i]] != i then call testFail("fail " + I2S(i) + ", " + I2S(Blub_x[test_b[i]])) endif set i = i + 1 endloop call testSuccess() endfunction function main takes nothing returns nothing call initGlobals() call init_test() endfunction function config takes nothing returns nothing endfunction