1if not modules then modules = { } end modules ['syst-con'] = {
2 version = 1.001,
3 comment = "companion to syst-con.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9local tonumber = tonumber
10local math = math
11local utfchar = utf.char
12local gsub = string.gsub
13
14converters = converters or { }
15local converters = converters
16
17local context = context
18local commands = commands
19local implement = interfaces.implement
20
21local formatters = string.formatters
22
23
24
25
26
27function converters.hexstringtonumber(n) tonumber(n,16) end
28function converters.octstringtonumber(n) tonumber(n, 8) end
29
30function converters.rawcharacter (n) utfchar(0x110000+n) end
31
32local f_lchexnumber = formatters["%x"]
33local f_uchexnumber = formatters["%X"]
34local f_lchexnumbers = formatters["%02x"]
35local f_uchexnumbers = formatters["%02X"]
36local f_octnumber = formatters["%03o"]
37local nicenumber = formatters["%0.6F"]
38
39local lchexnumber = function(n) if n < 0 then n = 0x100000000 + n end return f_lchexnumber (n) end
40local uchexnumber = function(n) if n < 0 then n = 0x100000000 + n end return f_uchexnumber (n) end
41local lchexnumbers = function(n) if n < 0 then n = 0x100000000 + n end return f_lchexnumbers(n) end
42local uchexnumbers = function(n) if n < 0 then n = 0x100000000 + n end return f_uchexnumbers(n) end
43local octnumber = function(n) if n < 0 then n = 0x100000000 + n end return f_octnumber (n) end
44
45converters.lchexnumber = lchexnumber
46converters.uchexnumber = uchexnumber
47converters.lchexnumbers = lchexnumbers
48converters.uchexnumbers = uchexnumbers
49converters.octnumber = octnumber
50converters.nicenumber = nicenumber
51
52implement { name = "hexstringtonumber", actions = { tonumber, context }, arguments = { "integer", 16 } }
53implement { name = "octstringtonumber", actions = { tonumber, context }, arguments = { "integer", 8 } }
54
55implement { name = "rawcharacter", actions = function(n) context(utfchar(0x110000+n)) end, arguments = "integer" }
56
57implement { name = "lchexnumber", actions = { lchexnumber, context }, arguments = "integer" }
58implement { name = "uchexnumber", actions = { uchexnumber, context }, arguments = "integer" }
59implement { name = "lchexnumbers", actions = { lchexnumbers, context }, arguments = "integer" }
60implement { name = "uchexnumbers", actions = { uchexnumbers, context }, arguments = "integer" }
61implement { name = "octnumber", actions = { octnumber, context }, arguments = "integer" }
62
63implement { name = "sin", actions = { math.sin, nicenumber, context }, arguments = "number" }
64implement { name = "cos", actions = { math.cos, nicenumber, context }, arguments = "number" }
65implement { name = "tan", actions = { math.tan, nicenumber, context }, arguments = "number" }
66
67implement { name = "sind", actions = { math.sind, nicenumber, context }, arguments = "number" }
68implement { name = "cosd", actions = { math.cosd, nicenumber, context }, arguments = "number" }
69implement { name = "tand", actions = { math.tand, nicenumber, context }, arguments = "number" }
70
71
72
73function commands.format(fmt,...) context((gsub(fmt,"@","%%")),...) end
74
75implement {
76 name = "formatone",
77 public = true,
78 protected = true,
79 arguments = "2 strings",
80 actions = function(f,s) context((gsub(f,"@","%%")),s) end,
81}
82 |