Skip to content

Instantly share code, notes, and snippets.

@east
Created July 10, 2015 12:22
Show Gist options
  • Save east/ec46c0219d24a319a328 to your computer and use it in GitHub Desktop.
Save east/ec46c0219d24a319a328 to your computer and use it in GitHub Desktop.
plugin system in nim
# 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