File: calculator.lua

package info (click to toggle)
minetest-mod-basic-robot-csm 0.0~git20190703.e082c6a-2
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 268 kB
  • sloc: makefile: 2
file content (26 lines) | stat: -rw-r--r-- 625 bytes parent folder | download
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
--calculator by rnd

if not init then
	init = true
	self.msg_filter("",false)
	say(minetest.colorize("red","#Calculator started. say ,1+1 or x=2;return x^0.5 "))
end

msg = self.sent_msg()
if msg and msg~="" then 
	local result,err;
	local f;
	if not string.find(msg,"return") then msg = "return " .. msg end
	f,err = _G.loadstring(msg);
	if err then 
		say("#compile error: " .. err) 
	else 
		err,result = pcall(f);
		if not result then
			say("#run error: " ..err)
		else
			result = tonumber(result)
			if result then say(minetest.colorize("lawngreen",msg .. " -> " .. result)) else say("empty result") end
		end
	end
end