Add files via upload

master
AiTechEye 2019-01-09 09:29:35 +01:00 committed by GitHub
parent b54622105b
commit 63a84afd8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 55 deletions

13
api.lua
View File

@ -76,6 +76,7 @@ was.compiler=function(input_text,user)
input_text=input_text:gsub("%)"," } ")
input_text=input_text:gsub("%[","")
input_text=input_text:gsub("%]","")
input_text=input_text:gsub("%%","")
local c
local data={}
@ -199,13 +200,19 @@ was.compiler=function(input_text,user)
--)
func=nil
data[ii].type="bracket end"
elseif data[ii].type=="symbol" then
--symbol
if not was.symbols[data[ii].content] then
return 'ERROR line '.. i ..': "' .. data[ii].content ..'" unknown symbol'
elseif data[ii].content=="--" then
ii=#v
end
elseif data[ii].type=="var" and data[ii].content=="next" then
if nexts==0 then
return 'ERROR line '.. i ..': no "for" to return to'
end
nexts=0
data[ii].forstate=true
end
ii=ii+1
end
@ -313,7 +320,9 @@ was.run=function(input,user)
was.userdata.index=i
was.userdata.var=VAR
if v[i].forstate then
if was.userdata.error then
return 'ERROR line '.. index ..': ' .. was.userdata.error
elseif v[i].forstate then
if v[i].content=="next" then
if forstate.i<forstate.e then

View File

@ -1,31 +1,11 @@
was={
functions={},
function_packed={},
info={
["!"]="Empty value",
["=="]="Equal (only used with if)",
["~="]="Equal (only used with if)",
[">"]="Greater then (only used with if)",
["<"]="Less then (only used with if)",
[">="]="Greater or equal (only used with if)",
["<="]="Less or equal (only used with if)",
},
info={},
privs={},
user={},
userdata={},
symbols={
["!"]=function()
if was.userdata.function_name=="if" then
return "!"
end
end,
[">"]=function() return ">" end,
["<"]=function() return "<" end,
["=="]=function() return "==" end,
["~="]=function() return "~=" end,
[">="]=function() return ">=" end,
["<="]=function() return "<=" end,
},
symbols={},
symbols_characters="#@=?!&{}%*+-/$<>|~^",
}

View File

@ -3,12 +3,17 @@
================= SYMBOLS =================
--]]
was.register_symbol("?",
function()
return was.userdata.name
end,
"return username"
)
was.register_symbol("?",function() return was.userdata.name end,"return username")
was.register_symbol("!", function() if was.userdata.function_name~="if" then was.userdata.error=" ! only able in if state" end end,"Empty value")
was.register_symbol(">", function() if was.userdata.function_name~="if" then was.userdata.error=" > only able in if state" end end,"Greater then (only used with if)" )
was.register_symbol("<", function() if was.userdata.function_name~="if" then was.userdata.error=" < only able in if state" end end,"Less then (only used with if)" )
was.register_symbol("<=", function() if was.userdata.function_name~="if" then was.userdata.error=" <= only able in if state" end end,"Less or equal (only used with if)" )
was.register_symbol(">=", function() if was.userdata.function_name~="if" then was.userdata.error=" >= only able in if state" end end,"Greater or equal (only used with if)" )
was.register_symbol("==", function() if was.userdata.function_name~="if" then was.userdata.error=" == only able in if state" end end,"Equal (only used with if)" )
was.register_symbol("~=", function() if was.userdata.function_name~="if" then was.userdata.error=" > only able in if state" end end,"Equal (only used with if)" )
was.register_symbol("!=",function() end, "var = nothing")
was.register_symbol("--",function() end, "Comment")
was.register_symbol("-",function() end, "Minus")
was.register_symbol("+=",function()
local i=was.userdata.index
@ -28,7 +33,6 @@ was.register_symbol("-=",function()
"var - n"
)
was.register_symbol("*=",function()
local i=was.userdata.index
if was.is_number(was.iuserdata(i-1)) and was.is_number(was.iuserdata(i+1)) then
@ -38,7 +42,6 @@ was.register_symbol("*=",function()
"var * n"
)
was.register_symbol("/=",function()
local i=was.userdata.index
if was.is_number(was.iuserdata(i-1)) and was.is_number(was.iuserdata(i+1)) then
@ -48,20 +51,6 @@ was.register_symbol("/=",function()
"var / n"
)
was.register_symbol("%=",function()
local i=was.userdata.index
if was.is_number(was.iuserdata(i-1)) and was.is_number(was.iuserdata(i+1)) then
return was.iuserdata(i-1) % was.iuserdata(i+1)
end
end,
"var % n"
)
was.register_symbol("!=",function()
end,
"var = nothing"
)
--[[
================= SERVER =================
--]]
@ -88,12 +77,12 @@ was.register_function("math.pi",{
})
was.register_function("math",{
info="Math + - * % ^ / ('-' 1 2 67...)",
info="Math + - * ^ / ('-' 1 2 67...)",
packed=true,
action=function(a)
local c=a[1]
local n=a[2]
if not (was.is_string(c) and c:len()==1 and string.find("%^+-*/",c)) then
if not (was.is_string(c) and c:len()==1 and string.find("^+-*/",c)) then
return
end
@ -109,8 +98,6 @@ was.register_function("math",{
n=n/a[i]
elseif c=="^" then
n=n^a[i]
elseif c=="%" then
n=n%a[i]
end
end
end
@ -344,7 +331,7 @@ was.register_function("nodetimer.start",{
local u=was.user[was.userdata.name]
if was.protected(pos) then
return
elseif not pos and n and u.nodepos and was.is_number(n) then
elseif not pos and n and u and u.nodepos and was.is_number(n) then
minetest.get_node_timer(u.nodepos):start(n)
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_number(n) and was.is_pos(pos) then
minetest.get_node_timer(pos):start(n)
@ -360,7 +347,7 @@ was.register_function("nodetimer.stop",{
local u=was.user[was.userdata.name]
if was.protected(pos) then
return
elseif not pos and n and u.nodepos then
elseif not pos and n and u and u.nodepos then
minetest.get_node_timer(u.nodepos):stop()
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_pos(pos) then
minetest.get_node_timer(pos):stop()
@ -378,7 +365,7 @@ was.register_function("mesecon.on",{
local u=was.user[was.userdata.name]
if was.protected(pos) then
return
elseif not pos and n and u.nodepos then
elseif not pos and n and u and u.nodepos then
mesecon.receptor_on(u.nodepos)
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_pos(pos) then
mesecon.receptor_on(pos)
@ -393,7 +380,7 @@ was.register_function("mesecon.off",{
local u=was.user[was.userdata.name]
if was.protected(pos) then
return
elseif not pos and n and u.nodepos then
elseif not pos and n and u and u.nodepos then
mesecon.receptor_off(u.nodepos)
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_pos(pos) then
mesecon.receptor_off(pos)
@ -406,9 +393,10 @@ was.register_function("mesecon.send",{
info="Send a mesecon signal (nothing or pos) to effect another node requires was privilege ",
action=function(pos)
local u=was.user[was.userdata.name]
if was.protected(pos) then
return
elseif not pos and n and u.nodepos then
elseif not pos and n and u and u.nodepos then
local p=u.nodepos
mesecon.receptor_on(p)
minetest.after(1, function(p)