BigArray:pop()

説明

配列(BigArray)の末尾の値を取り出します。psuh()のパラメーターはBigArrayオブジェクトを指定します。なお、配列が空の場合はundefinedではなく0の値を返す点には注意してください。

[以下のJavaScriptプログラムをダウンロード]

// BigArray:Pop(BigArray)
// BigArray(adrs)
function BigAry(a){
this.adrs=a; // EEPROM Address
this.length=0; // Length
this.set=function(idx,n){ // Set Data
var adrs=this.adrs+idx*4; // EEPROM Address+Index
i2cw(0x50|(((adrs>>16)&1)<<2), (adrs&0xff00)>>8,adrs&0xff, (n&0xFF000000)>>24,(n&0xFF0000)>>16,(n&0xFF00)>>8,n&0xFF);
if ((idx+1)>this.length){ this.length=idx+1; }
};
this.get=function(idx){ // Get Data
var adrs=this.adrs+idx*4; // EEPROM Address+Index
var t1,t2,t3,t4,d=0x50|(((adrs>>16)&1)<<2);
i2cw(d,(adrs&0xff00)>>8,adrs&255);
i2cr(d,t1,t2,t3,t4);
return (t1<<24)|(t2<<16)|(t3<<8)|t4;
};
}
// BigArray Pop
function pop(ary){
if(ary.length<1){ return 0; }
ary.length=ary.length-1;
return ary.get(ary.length);
}
// Sample Code
var myAry=new BigAry(0);
myAry.set(0,0x31323334);
sleep(10);
myAry.set(1,0x35363738);
sleep(10);
myAry.set(2,0x39404142);
sleep(10);
var n=pop(myAry);
log(myAry.length,":",n,"\n");
var n=pop(myAry);
log(myAry.length,":",n,"\n");
var n=pop(myAry);
log(myAry.length,":",n,"\n");

目次に戻る