Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
forked from carvalho/numlua
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseeall.lua
More file actions
Latest commit
62 lines (54 loc) · 1.39 KB
/
Copy pathseeall.lua
File metadata and controls
62 lines (54 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--[[
-- seeall.lua
-- Easy prototyping in NumericLua
-- Luis Carvalho (lexcarvalho@gmail.com)
-- See Copyright Notice in numlua.h
--]]
require"numlua"
pcall(require, "help")
localclasses= {"math", "mathx", "complex", "matrix"}
localwords=setmetatable({}, {__index=function() return0end})
for_, cinpairs(classes) do
forkinpairs(_G[c]) do
words[k] =words[k] +1
end
end
localnltype=numlua.type
localfunctionregistermath (name)
_G[name] =function (x, ...)
localxtype=nltype(x)
ifxtype=="number" then
localf=math[name] ormathx[name] orcomplex[name]
returnf(x, ...)
elseifxtype=="complex" then
returncomplex[name](x, ...)
else
returnmatrix[name](x, ...)
end
end
end
localregister=function (t, prefix)
fork, vinpairs(t) do
ifnot_G[k] then
_G[k] =v
elseifprefixthen
_G[prefix..k] =v
end
end
end
-- register common math functions first
fork, vinpairs(words) do
ifv>1then-- conflict?
registermath(k) -- register common function
end
end
register(math, "x")
register(mathx, "x")
register(complex, "c")
register(matrix, "m")
register(stat, "s")
register(rng, "r") -- conflicts with matrix: new, copy
type=numlua.type-- override
opmode=numlua.opmode
-- set matrix __tostring to `pretty`: more convenient for interpreter
getmetatable(matrix(1)).__tostring=matrix.pretty