summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-08-08 22:54:29 +0000
committerKarl Berry <karl@freefriends.org>2015-08-08 22:54:29 +0000
commit531d43fafa269c546d587eaca6cd14adcd11914f (patch)
tree1883933af984c60254e6d9d1bd955a76748cb827 /Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua
parent877e963d44f039783cb9227d90c911866c780961 (diff)
pgf (8aug15)
git-svn-id: svn://tug.org/texlive/trunk@38079 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua')
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua45
1 files changed, 44 insertions, 1 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua
index dcfb468d063..aaa7f648a51 100644
--- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua
@@ -7,7 +7,7 @@
--
-- See the file doc/generic/pgf/licenses/LICENSE for more information
--- @release $Header: /cvsroot/pgf/pgf/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua,v 1.5 2013/04/04 20:43:45 tantau Exp $
+-- @release $Header: /cvsroot/pgf/pgf/generic/pgf/graphdrawing/lua/pgf/gd/lib.lua,v 1.6 2014/02/24 10:40:32 tantau Exp $
@@ -351,6 +351,49 @@ function lib.class(t)
end
+
+---
+-- Returns a method that is loaded only on demand for a class.
+--
+-- The idea behind this function is that you may have a class (or just
+-- a table) for which some methods are needed only seldomly. In this
+-- case, you can put these methods in a separate file and then use
+-- |ondemand| to indicate that the methods are found in a
+-- another file.
+--
+--\begin{codeexample}[code only]
+-- -- File Foo.lua
+-- local Foo = {}
+-- function Foo.bar () ... end
+-- function Foo.bar2 () ... end
+-- Foo.bar3 = lib.ondemand("Foo_extra", Foo, "bar3")
+-- Foo.bar4 = lib.ondemand("Foo_extra", Foo, "bar4")
+--
+-- return Foo
+--
+-- -- Foo_extra.lua
+-- local Foo = require "Foo"
+-- function Foo.bar3 () ... end
+-- function Foo.bar4 () ... end
+--\end{codeexample}
+--
+-- @param filename The name of the file when extra methods are
+-- located.
+-- @param table The table for which the missing functions should be
+-- loaded when they are accessed.
+-- @param method The name of the method.
+--
+-- @return A function that, when called, loads the filename using
+-- |require| and, then, forwards the call to the method.
+
+function lib.ondemand(filename, table, name)
+ return function(...)
+ require (filename)
+ return table[name] (...)
+ end
+end
+
+
-- Done
return lib \ No newline at end of file