1%D \module 2%D [ file=luatex-basics, 3%D version=2009.12.01, 4%D title=\LUATEX\ Support Macros, 5%D subtitle=Attribute Allocation, 6%D author=Hans Hagen, 7%D date=\currentdate, 8%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] 9 10%D As soon as we feel the need this file will file will contain an extension 11%D to the standard plain register allocation. For the moment we stick to a 12%D rather dumb attribute allocator. We start at 256 because we don't want 13%D any interference with the attributes used in the font handler. 14 15\ifx\newattribute\undefined \else \endinput \fi 16 17\newcount \lastallocatedattribute \lastallocatedattribute=255 18 19\def\newattribute#1% 20 {\global\advance\lastallocatedattribute 1 21 \attributedef#1\lastallocatedattribute} 22 23% maybe we will have luatex-basics.lua some day for instance when more 24% (pdf) primitives have moved to macros) 25 26 27 28 gadgets = gadgets or { } % reserved namespace 29 30 gadgets.functions = { } 31 local registered = {} 32 33 function gadgets.functions.reverve() 34 local numb = token.scan_int() 35 local name = token.scan_string() 36 local okay = string.gsub(name,"[\string\\ ]","") 37 registered[okay] = numb 38 texio.write_nl("reserving lua function '"..okay.."' with number "..numb) 39 end 40 41 function gadgets.functions.register(name,f) 42 local okay = string.gsub(name,"[\string\\ ]","") 43 local numb = registered[okay] 44 if numb then 45 texio.write_nl("registering lua function '"..okay.."' with number "..numb) 46 lua.get_functions_table()[numb] = f 47 else 48 texio.write_nl("lua function '"..okay.."' is not reserved") 49 end 50 end 51 52 53 54\newcount\lastallocatedluafunction 55 56\def\newluafunction#1% 57 {\ifdefined#1\else 58 \global\advance\lastallocatedluafunction 1 59 \global\chardef#1\lastallocatedluafunction 60 gadgets.functions.reserve()#1{\detokenize{#1}}% 61 \fi} 62 63% an example of usage (if we ever support it it will go to the plain gadgets module): 64% 65% \newluafunction\UcharcatLuaOne 66% \newluafunction\UcharcatLuaTwo 67% 68% \directlua { 69% 70% local cct = nil 71% local chr = nil 72% 73% gadgets.functions.register("UcharcatLuaOne",function() 74% chr = token.scan_int() 75% cct = tex.getcatcode(chr) 76% tex.setcatcode(chr,token.scan_int()) 77% tex.sprint(unicode.utf8.char(chr)) 78% end) 79% 80% gadgets.functions.register("UcharcatLuaTwo",function() 81% tex.setcatcode(chr,cct) 82% end) 83% 84% } 85% 86% \def\Ucharcat 87% {\expandafter\expandafter\expandafter\luafunction 88% \expandafter\expandafter\expandafter\UcharcatLuaTwo 89% \luafunction\UcharcatLuaOne} 90% 91% A:\the\catcode65:\Ucharcat 65 11:A:\the\catcode65\par 92% A:\the\catcode65:\Ucharcat 65 5:A:\the\catcode65\par 93% A:\the\catcode65:\Ucharcat 65 11:A:\the\catcode65\par 94 95\endinput 96 |