1%D \module 2%D [ file=luat-usr, 3%D version=2005.08.11,% moved from luat-ini 4%D title=\CONTEXT\ Lua Macros, 5%D subtitle=Initialization, 6%D author=Hans Hagen, 7%D date=\currentdate, 8%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] 9%C 10%C This module is part of the \CONTEXT\ macro||package and is 11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 12%C details. 13 14\writestatus{loading}{ConTeXt Lua Macros / Userspace} 15 16\unprotect 17 18\registerctxluafile{luat-usr}{autosuffix} 19 20%D A few goodies: 21%D 22%D \startbuffer 23%D \luascript { context("foo 1:") context(i) } 24%D \luathread {test} { i = 10 context("bar 1:") context(i) } 25%D \luathread {test} { context("bar 2:") context(i) } 26%D \luathread {test} {} 27%D \luathread {test} { context("bar 3:") context(i) } 28%D \luascript { context("foo 2:") context(i) } 29%D \stopbuffer 30%D 31%D \typebuffer \startlines \getbuffer \stoplines 32 33% \luascript % defined at the lua end 34% \luathread % defined at the lua end 35 36%D \macros 37%D {definenamedlua} 38%D 39%D We provide an interface for defining instances. We don't have the definers yet 40%D so we do it low level: 41 42\def\s!lua {lua} 43\def\s!code {code} 44\def\s!data {data} 45\def\s!start{start} 46\def\s!stop {stop} 47 48%D Beware: because \type {\expanded} is een convert command, the error message will 49%D show \type{<inserted text>} as part of the message. 50 51\installsystemnamespace{luacode} 52 53\permanent\tolerant\protected\def\definenamedlua[#1]#*[#2]% 54 {\ifarguments \orelse \ifcsname\??luacode#1\endcsname \else 55 \bgroup 56 % 57 \edef\m_syst_lua_name{lua_code_#1}% 58 % 59 {#1}{#2}{\m_syst_lua_name}% 60 % 61 \frozen\instance\protected\xdefcsname\s!start#1\s!code\endcsname 62 {\begingroup 63 \obeyluatokens 64 \csname\??luacode#1\endcsname}% 65 % 66 \aliased\gletcsname\s!stop#1\s!code\endcsname\relax 67 % 68 \normalexpanded{\xdefcsname\??luacode#1\endcsname##1\csname\s!stop#1\s!code\endcsname}% 69 {\noexpand\expandafter\endgroup 70 \noexpand\expandafter 71 \expandafter\noexpand\csname clf_\m_syst_lua_name\endcsname 72 \noexpand\expandafter{\noexpand\normalexpanded{##1}}}% 73 \frozen\instance\gletcsname#1\s!code\expandafter\endcsname\csname clf_\m_syst_lua_name\endcsname 74 \egroup 75 \fi} 76 77%D We predefine a few. 78 79% \definenamedlua[module][module instance] % not needed 80 81\appendtoks 82 \definenamedlua[user] [private user] 83 \definenamedlua[third] [third party module] 84 \definenamedlua[isolated][isolated] 85\to \everyjob 86 87%D In practice this works out as follows: 88%D 89%D \startbuffer 90%D \startluacode 91%D context("LUA") 92%D \stopluacode 93%D 94%D \startusercode 95%D global.context("USER 1") 96%D context.par() 97%D context("USER 2") 98%D context.par() 99%D if characters then 100%D context("ACCESS directly") 101%D elseif global.characters then 102%D context("ACCESS via global") 103%D else 104%D context("NO ACCESS at all") 105%D end 106%D context.par() 107%D if bogus then 108%D context("ACCESS directly") 109%D elseif global.bogus then 110%D context("ACCESS via global") 111%D else 112%D context("NO ACCESS at all") 113%D end 114%D context.par() 115%D \stopusercode 116%D \stopbuffer 117%D 118%D \typebuffer 119 120\protect \endinput 121 |