lm-helpers.lua - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/lm-helpers.lua
blob: 098971fa9ce06b01f11295715e8d56cd4cd1798e (plain)
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
62
63
64
65
local LM = {}
local var_name = require 'lm-expr'
local factor_mt
local function mul_factor(a, b)
	local c = {value= a.value .. ":" .. b.value}
	return setmetatable(c, factor_mt)
end
factor_mt = {
	__mul = mul_factor,
}
function LM.factor(name)
	local t = {name= name, value = ""}
	return setmetatable(t, factor_mt)
end
function LM.eval_test(...)
	local inf = {np = select('#', ...)}
	inf.class = {}
	for k= 1, inf.np do
		local v = select(k, ...)
		inf.class[k] = (type(v) == 'number' and 1 or 0)
	end
	return inf
end
function LM.eval_func(inf, pt, i, ...)
 for k = 1, inf.np do
 local x = select(k, ...)
 local value = (inf.class[k] == 1 and x or x.value)
 gdt.set(pt, i, k, value)
 end
end
LM.var_name = var_name
local function expr_to_name(expr)
	if type(expr) == 'table' then
		return expr.name
	else
		local base = '(average)'
		local minus = expr < 0 and '- ' or ''
		if expr == 1 or expr == -1 then
			return string.format("%s%s", minus, base)
		else
			return string.format("%s%s / %g", minus, base, math.abs(expr))
		end
	end
end
function LM.find_names(...)
	local n = select("#", ...)
	local names = {}
	for k = 1, n do
		local expr = select(k, ...)
		names[k] = expr_to_name(expr)
	end
	return names
end
return LM
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月11日 09:04:32 +0000

AltStyle によって変換されたページ (->オリジナル) /