Created
July 10, 2015 12:22
-
-
Save east/ec46c0219d24a319a328 to your computer and use it in GitHub Desktop.
plugin system in nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A plugin interface might look like this | |
type PluginInterface = ref object of RootObj | |
discard # here might be some vars | |
# virtual methods (not implemented) | |
# on irc message | |
method onMsg(this: PluginInterface, msg: string) = | |
discard | |
# on user join | |
method onUserJoin(this: PluginInterface, user: string) = | |
discard | |
# Let's write a plugin | |
type CoolPlugin = ref object of PluginInterface | |
userCount: int | |
# implement / overwrite methods | |
method onMsg(this: CoolPlugin, msg: string) = | |
# display message | |
echo ("we got a messsage: ", msg) | |
method onUserJoin(this: CoolPlugin, user: string) = | |
# count users | |
this.userCount.inc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment