int cmd_print(struct ldb_context *lctx, const char *cmdbuffer) { if (lctx->lprog->status != RUNNING) { printf("program not running! %d\n", lctx->lprog->status); return CMD_ERR; } printf("btop %d\n", lua_gettop(lctx->lprog->L)); //try local vairables if(find_locals(lctx->lprog->L, lctx->lprog->ar, cmdbuffer)) { printf("local %s = ", cmdbuffer); print_luavar(lctx->lprog->L, -1, 1); printf("\n"); lua_pop(lctx->lprog->L, 1); } else if(find_globals(lctx->lprog->L, cmdbuffer)) { printf("global %s = ", cmdbuffer); print_luavar(lctx->lprog->L, -1, 1); printf("\n"); lua_pop(lctx->lprog->L, 1); } else if(find_upvalues(lctx->lprog->L, lctx->lprog->ar, cmdbuffer)) { printf("upvalue %s = ", cmdbuffer); print_luavar(lctx->lprog->L, -1, 1); printf("\n"); lua_pop(lctx->lprog->L, 1); } else { printf("%s = nil\n",cmdbuffer); } printf("atop %d\n", lua_gettop(lctx->lprog->L)); return CMD_OK; }
int main ( int argc, char **argv ) { yyparse(); simplify_tree ( &root, root ); // node_print(root, 0); find_globals(); size_t n_globals = tlhash_size(global_names); symbol_t *global_list[n_globals]; tlhash_values ( global_names, (void **)&global_list ); for ( size_t i=0; i<n_globals; i++ ) if ( global_list[i]->type == SYM_FUNCTION ) bind_names ( global_list[i], global_list[i]->node ); // print_globals(); generate_program (); destroy_subtree ( root ); destroy_symtab(); }