Skip to content

Instantly share code, notes, and snippets.

@kmaed
Created October 9, 2012 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmaed/3857424 to your computer and use it in GitHub Desktop.
Save kmaed/3857424 to your computer and use it in GitHub Desktop.
2012/10/08 の失敗例2
%#! luatex
\catcode`\@=11
\def\len@begin{\directlua{
local len_count = 0
local len_flag = true
while len_flag do
local t = token.get_next()
if token.csname_name(t) == 'len@end' then
len_flag = false
print(); print()
print('len(yourcode)=' .. tostring(len_count))
end
len_count = len_count + 1
end
}}
\def\length#1{\len@begin#1\len@end#1}
\length{% ここから
\def\numtohex#1{%
\count@#1\divide\count@\sixt@@n
\uccode`<\numtohex@aux
\count@\numexpr#1-\count@*\sixt@@n
\uccode`>\numtohex@aux
\uppercase{\def\result{<>}}}%
\def\numtohex@aux{\numexpr\count@+`0\ifnum\count@>9+7\fi}% ここまで
}
\catcode`\@=12
\numtohex{042}\show\result %==>2A
\numtohex{`\\}\show\result %==>5C
\count0=3 \numtohex{\count0}\show\result %==>03
\bye
@kmaed
Copy link
Author

kmaed commented Oct 9, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment