__SYMBOLS = { }; __DICT = { }; -- the keys will be strings (the commands), and values will be true function add(command) if not __DICT[command] then -- the command isn't in the list yet __SYMBOLS[#__SYMBOLS + 1] = command; __DICT[command] = true; -- now it is end end function remove(command) __DICT[command] = nil; -- remove command from the list for i,v in ipairs(__SYMBOLS) do if v == command then table.remove(__SYMBOLS,i); -- also remove it from __SYMBOLS break; end end end -- deal with the Lua functions do local f,g = registerSymbol,unregisterSymbol; registerSymbol = function(sym,addr,opt) if sym and addr then add(string.format('unregistersymbol(%s)',sym)); end return f(sym,addr,opt); end unregisterSymbol = function(sym) remove(string.format('unregistersymbol(%s)',sym)); return g(sym); end RegisterSymbol,UnregisterSymbol = registerSymbol,unregisterSymbol; end local function onAutoAssemble(script,syntax) local lua_block = false; for i = 0,script.count - 1 do local line = script[i]:lower():gsub('^%s+',''); if lua_block then if line:find'{$asm}' then lua_block = false; end else if line:find'^registersymbol%(' then local command = 'un'..line:match'^registersymbol%(.-%)'; add(command); elseif line:find'^unregistersymbol%(' then local command = line:match'^unregistersymbol%(.-%)'; remove(command); end if line:find'{$lua}' then lua_block = true; end end end end registerAutoAssemblerPrologue(onAutoAssemble,true); local main = getMainForm(); local btn = createButton(main); btn.width,btn.height,btn.top,btn.left = 100,30,290,460; btn.caption = 'clear U-symbols'; btn.onClick = function() autoAssemble(table.concat(__SYMBOLS,'\n')); end