Software /
code /
prosody
Annotate
util/pluginloader.lua @ 2848:b2f367f16eb8
util.stanza: stanza.error_reply(): Fix to put the correct namespace on <text>
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 31 Jan 2010 19:27:52 +0000 |
parent | 1522:569d58d21612 |
child | 2276:d9302be05f86 |
child | 2923:b7049746bd29 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
1 -- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
4 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1441
diff
changeset
|
8 |
1359
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local plugin_dir = CFG_PLUGINDIR or "./plugins/"; |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local io_open = io.open; |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local loadstring = loadstring; |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 module "pluginloader" |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local function load_file(name) |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local file, err = io_open(plugin_dir..name); |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 if not file then return file, err; end |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 local content = file:read("*a"); |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 file:close(); |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 return content, name; |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 end |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 function load_resource(plugin, resource) |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 if not resource then |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 resource = "mod_"..plugin..".lua"; |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 end |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 local content, err = load_file(plugin.."/"..resource); |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 if not content then content, err = load_file(resource); end |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 -- TODO add support for packed plugins |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 return content, err; |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 end |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 function load_code(plugin, resource) |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 local content, err = load_resource(plugin, resource); |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 if not content then return content, err; end |
1441
9c6c7aa5dc60
util.pluginloader: Append "@" to chunk names (fixes weird formatting in plugin tracebacks)
Waqas Hussain <waqas20@gmail.com>
parents:
1387
diff
changeset
|
38 return loadstring(content, "@"..err); |
1359
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 end |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 |
015d624a2a71
util.pluginloader: Initial commit - a plugin resource loader
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 return _M; |