如何在不使用LPeg模块的情况下在lua中输入用户输入?

时间:2016-12-05 00:39:49

标签: lua lexer

我查看了其他答案(即安装和使用LPeg),但没有找到合适的解释。我在Lua中创建了一个非常基本的编程语言(我知道该怎么做),但只需要一些词法分析器来处理某些事情,比如变量。这是我的两个函数,我在命令(cmd)函数中使用了string.match:

function screen (action, actionvar) 
if action = "clear" then
os.execute("clear")
elseif action = "cls" then
os.execute("cls")
elseif action = "showText" then
print(actionvar)
end
end


function command (cmd)
if string.match(cmd, "screen") then
    if string.match(cmd, "clear") then
        screen(clear)
    elseif string.match(cmd, "cls") then
        screen(cls)
    end
    -- it must be showText or improper cmd.
    if string.match(cmd, "showText") then

    else
    print("Error: Unrecognized screen command.")
    return null
    end
end
end

0 个答案:

没有答案