@@ -929,34 +929,38 @@ void AddToTable(Function* F, DecTable* tbl, const char* value, const char* key)
929929 AddToList (list , (ListItem * )item );
930930}
931931
932- void SetList (Function * F , int a , int b , int c ) {
933- int i ;
932+ int SetList (Function * F , int a , int b , int c ) {
933+ int i = 1 , j ;
934934 DecTable * tbl = (DecTable * )FindFromListTail (& (F -> tables ), (ListItemCmpFn )MatchTable , & a );
935935 if (tbl == NULL ) {
936- sprintf (errortmp , "No list found for R%d , SetList fails" , a );
937- SET_ERROR (F , errortmp );
938- return ;
936+ UnsetPending (F , a );
939937 }
940938 if (b == 0 ) {
941939 const char * rstr ;
942940 i = 1 ;
943941 while (1 ) {
944942 rstr = GetR (F , a + i );
945943 if (error )
946- return ;
944+ return tbl ? 0 : i ;
947945 if (strcmp (rstr ,".end" ) == 0 )
948946 break ;
949- AddToTable (F , tbl , rstr , NULL ); // Lua5.1 specific TODO: it's not really this :(
947+ if (tbl ) {
948+ AddToTable (F , tbl , rstr , NULL ); // Lua5.1 specific TODO: it's not really this :(
949+ }
950950 i ++ ;
951951 };
952952 } //should be {...} or func(func()) ,when b == 0, that will use all avaliable reg from R(a)
953953
954- for (i = 1 ; i <= b ; i ++ ) {
955- const char * rstr = GetR (F , a + i );
954+ for (j = 1 ; j <= b ; j ++ ) {
955+ const char * rstr = GetR (F , a + j );
956956 if (error )
957- return ;
958- AddToTable (F , tbl , rstr , NULL ); // Lua5.1 specific TODO: it's not really this :(
957+ return tbl ? 0 : i + j - 2 ;
958+ if (tbl ) {
959+ AddToTable (F , tbl , rstr , NULL ); // Lua5.1 specific TODO: it's not really this :(
960+ }
959961 }
962+
963+ return tbl ? 0 : i + j - 2 ;
960964}
961965
962966void UnsetPending (Function * F , int r ) {
@@ -3026,7 +3030,31 @@ char* ProcessCode(Proto* f, int indent, int func_checking, char* funcnumstr) {
30263030 }
30273031#endif
30283032 }
3029- TRY (SetList (F , a , b , c ));
3033+
3034+ const char * astr ;
3035+ const char * cstr ;
3036+ int setlist ;
3037+ /*
3038+ * first try to add into a list
3039+ */
3040+ TRY (setlist = SetList (F , a , b , c ));
3041+ if (setlist ) {
3042+ /*
3043+ * if failed, just output an assignment
3044+ */
3045+ for (int i = setlist ; i >= 1 ; i -- ) {
3046+ TRY (astr = GetR (F , a ));
3047+ if (isIdentifier (astr )) {
3048+ StringBuffer_set (str , astr );
3049+ } else {
3050+ StringBuffer_printf (str , "(%s)" , astr );
3051+ }
3052+ StringBuffer_addPrintf (str , "[%d]" , (c - 1 )* 50 + i ); // todo: s/50/LFS_SIZE or w/e
3053+ PENDING (a + i ) = 1 ;
3054+ TRY (cstr = GetR (F , a + i ));
3055+ TRY (AssignGlobalOrUpvalue (F , StringBuffer_getRef (str ), cstr ));
3056+ }
3057+ }
30303058 break ;
30313059 }
30323060#if LUA_VERSION_NUM == 501
0 commit comments