Compare commits

..

No commits in common. "3d8b09167b1db74b5e2370edc3c199170b9fe42b" and "319779a16c8ab7483af23f8e5dbbc2346f74ee17" have entirely different histories.

3 changed files with 4 additions and 33 deletions

7
main.c
View File

@ -32,12 +32,7 @@ static size_t native_print(LVM *lvm, void *ud, size_t argn, set_LValueU *heap, L
static size_t table_insert(LVM *lvm, void *ud, size_t argn, set_LValueU *heap, LRegSet *regset) {
LTable *tbl = (LTable*) (regset->regs[0].u & ~LTAG_MASK);
if(argn == 2) {
ltable_insert(tbl, regset->regs[1], 0);
} else if(argn > 2) {
size_t idx = lvalue_to_int32(regset->regs[1]);
ltable_insert(tbl, regset->regs[2], idx);
}
ltable_insert(tbl, regset->regs[1], 0);
return 0;
}

17
table.h
View File

@ -241,20 +241,9 @@ static inline size_t ltable_len(LTable *self) {
return ret;
}
static inline bool ltable_insert(LTable *self, LValue val, size_t index) {
static inline void ltable_insert(LTable *self, LValue val, size_t index) {
lrwl_write_lock(&self->lock);
size_t len = ltable_len_nolock(self);
if(index == 0) {
index = len + 1;
}
bool success = false;
if(index <= len + 1) {
for(size_t i = len; i >= index; i--) {
ltable_set_nolock(self, lvalue_from_int32(i + 1), ltable_get_nolock(self, lvalue_from_int32(i)));
}
ltable_set_nolock(self, lvalue_from_int32(index), val);
success = true;
}
index = ltable_len_nolock(self) + 1;
ltable_set_nolock(self, lvalue_from_int32(index), val);
lrwl_write_unlock(&self->lock);
return success;
}

View File

@ -1,13 +0,0 @@
t = {}
for i = 50, 1, -1 do
table.insert(t, 1, i)
end
for i = 50, 1, -1 do
table.insert(t, i)
end
for i = 1, #t do
print(t[i])
end