Originally Posted by pelf
Using rawset lets me set the value directly without triggering the stuff that would prevent this from working as it looks like it should.
|
Not exactly a solid explanation. You're talking of avoiding the
__newindex metamethod in which if one exists, it would need to allow writing to the table or else break the slash command system. What's happening in the code is you're copying the function from the metatable and inserting it back into the table itself. This lets
ChatFrame_ImportAllListsToHash() see the function and reprocess it. In the long run,
rawset() isn't necessary as the following deceptively works fine as-is without the overhead of calling a global function.
Code:
SlashCmdList.UI_ERRORS_OFF=SlashCmdList.UI_ERRORS_OFF;
SlashCmdList.UI_ERRORS_ON=SlashCmdList.UI_ERRORS_ON;
Note since the indices don't exist, it pulls the functions from the metatable and creates the entry in the base table, not back into the metatable.
If you really wanted to bypass setting all the globals, you could just inject the function directly into hash.
Code:
hash_SlashCmdList["/ERROROFF"]=SlashCmdList.UI_ERRORS_OFF;
hash_SlashCmdList["/ERROFF"]=SlashCmdList.UI_ERRORS_OFF;
hash_SlashCmdList["/ERRORON"]=SlashCmdList.UI_ERRORS_ON;
hash_SlashCmdList["/ERRON"]=SlashCmdList.UI_ERRORS_ON;
Note the indices need to be in uppercase as all entered slash commands are checked this way.