summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/cld/cld-macros.tex
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-01-12 17:15:43 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-01-12 17:15:43 +0100
commit52c5102fab837626fe9bb359b3eda6066e1a968e (patch)
tree6dfd2d9eeafa7aaa7fea55394e496762b2f8a489 /doc/context/sources/general/manuals/cld/cld-macros.tex
parentd0edf3e90e8922d9c672f24ecdc5d44fe2716f31 (diff)
downloadcontext-52c5102fab837626fe9bb359b3eda6066e1a968e.tar.gz
2018-01-12 16:04:00
Diffstat (limited to 'doc/context/sources/general/manuals/cld/cld-macros.tex')
-rw-r--r--doc/context/sources/general/manuals/cld/cld-macros.tex56
1 files changed, 56 insertions, 0 deletions
diff --git a/doc/context/sources/general/manuals/cld/cld-macros.tex b/doc/context/sources/general/manuals/cld/cld-macros.tex
index de677e2c1..a177db9f8 100644
--- a/doc/context/sources/general/manuals/cld/cld-macros.tex
+++ b/doc/context/sources/general/manuals/cld/cld-macros.tex
@@ -163,6 +163,62 @@ is handled automatically.
\stopsection
+\startsection[title=Looking inside]
+
+If needed you can access the body of a macro. Take for instance:
+
+\startbuffer
+\def\TestA{A}
+\def\TestB{\def\TestC{c}}
+\def\TestC{C}
+\stopbuffer
+
+\typebuffer \getbuffer
+
+The following example demonsttaies how we can look inside these macros. You need
+to be aware of the fact that the whole blob of \LUA\ codes is finished before we
+return to \TEX, so when we pipe the meaning of \type {TestB} back to \TEX\ it
+only gets expanded afterwards. We can use a function to get back to \LUA. It's
+only then that the meaning of \type {testC} is changed by the (piped) expansion
+of \type {TestB}.
+
+\startbuffer
+\startluacode
+context(tokens.getters.macro("TestA"))
+context(tokens.getters.macro("TestB"))
+context(tokens.getters.macro("TestC"))
+tokens.setters.macro("TestA","a")
+context(tokens.getters.macro("TestA"))
+context(function()
+ context(tokens.getters.macro("TestA"))
+ context(tokens.getters.macro("TestB"))
+ context(tokens.getters.macro("TestC"))
+end)
+\stopluacode
+\stopbuffer
+
+\typebuffer \getbuffer
+
+Here is another example:
+
+\startbuffer
+\startluacode
+if tokens.getters.macro("fontstyle") == "rm" then
+ context("serif")
+else
+ context("unknown")
+end
+\stopluacode
+\stopbuffer
+
+\typebuffer
+
+Of course this assumes that you have some knowledge of the \CONTEXT\ internals.
+
+\getbuffer
+
+\stopsection
+
\stopchapter
\stopcomponent