Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions luadec/decompile.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,34 +929,38 @@ void AddToTable(Function* F, DecTable* tbl, const char* value, const char* key)
AddToList(list, (ListItem*)item);
}

void SetList(Function* F, int a, int b, int c) {
int i;
int SetList(Function* F, int a, int b, int c) {
int i = 1, j;
DecTable* tbl = (DecTable*)FindFromListTail(&(F->tables), (ListItemCmpFn)MatchTable, &a);
if (tbl == NULL) {
sprintf(errortmp, "No list found for R%d , SetList fails", a);
SET_ERROR(F, errortmp);
return;
UnsetPending(F, a);
}
if (b == 0) {
const char* rstr;
i = 1;
while (1) {
rstr = GetR(F, a + i);
if (error)
return;
return tbl ? 0 : i;
if (strcmp(rstr,".end") == 0)
break;
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
if (tbl) {
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
}
i++;
};
} //should be {...} or func(func()) ,when b == 0, that will use all avaliable reg from R(a)

for (i = 1; i <= b; i++) {
const char* rstr = GetR(F, a + i);
for (j = 1; j <= b; j++) {
const char* rstr = GetR(F, a + j);
if (error)
return;
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
return tbl ? 0 : i + j - 2;
if (tbl) {
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
}
}

return tbl ? 0 : i + j - 2;
}

void UnsetPending(Function* F, int r) {
Expand Down Expand Up @@ -3026,7 +3030,31 @@ char* ProcessCode(Proto* f, int indent, int func_checking, char* funcnumstr) {
}
#endif
}
TRY(SetList(F, a, b, c));

const char *astr;
const char *cstr;
int setlist;
/*
* first try to add into a list
*/
TRY(setlist = SetList(F, a, b, c));
if (setlist) {
/*
* if failed, just output an assignment
*/
for (int i = setlist; i >= 1; i--) {
TRY(astr = GetR(F, a));
if (isIdentifier(astr)) {
StringBuffer_set(str, astr);
} else {
StringBuffer_printf(str, "(%s)", astr);
}
StringBuffer_addPrintf(str, "[%d]", (c-1)*50+i); // todo: s/50/LFS_SIZE or w/e
PENDING(a+i) = 1;
TRY(cstr = GetR(F, a+i));
TRY(AssignGlobalOrUpvalue(F, StringBuffer_getRef(str), cstr));
}
}
break;
}
#if LUA_VERSION_NUM == 501
Expand Down