SparkMod/SparkMod — pull request #2 by Jahze (2013-07-07 13:39:59+00:00)
Title: Plugin loading bug fixes

There was still an issue with sm plugins refresh because dependent plugins automatically load their dependencies:

[SM] Plugin "map_vote" failed to load: lua/SparkMod/plugin_base.lua:119: Plugin library name unavailable: MapVote
stack traceback:
[C]: in function 'error'
lua/SparkMod/plugin_base.lua:119: in function '__newindex'
lua/SparkMod/plugin.lua:83: in function '__newindex'
lua/SparkMod/plugins/map_vote.lua:51: in function 'load_file'
lua/SparkMod/plugin.lua:303: in function
[SM] Plugin failed to load: map_vote
[SM] 6 plugins successfully loaded

----

The other issue is that plugins could be initialized twice:

[SM] Unloaded all plugins
[DEBUG] Attempting to load rtv dependency: map_vote
[DEBUG] Plugin "rtv" is no longer waiting on dependency: map_vote
[DEBUG] Plugin "rtv" can now be initialized
Plugin initialized: rtv
[map_vote] Plugin library name: MapVote
Plugin initialized: map_vote
[DEBUG] map_vote was loaded successfully, continuing to load: rtv
Plugin initialized: rtv
[SM] Loaded plugin successfully: rtv

This is because Plugin.Initialize can be called from two places:

1. In Plugin.Load after a dependency has been loaded any dependent plugins are initialized
2. At the end of Plugin.Load

There is some funky stuff going on with coroutine in the plugin loading code, and I don't have enough time to fully figure that out right now, so I'm not entirely sure if both of these calls are necessary. I think that it would be better to remove the call I've noted as 1. above, if possible. Either way this will work as a fix for now.