Code: Select all
--main.lua
function love.load(args)
local lib = require "lib"
local act = lib.connect()
--act:read("action item to entity")
act:read("sell apple to alpha")
act:read("sell red_potion to alpha")
print()
act:read("sell apple, steel to alpha")
act:read("sell apple , steel to alpha")
act:read("sell apple ,steel to alpha")
act:read("sell apple,steel to alpha")
print()
act:read("sell red_potion, steel to alpha")
act:read("sell red_potion , steel to alpha")
act:read("sell red_potion ,steel to alpha")
act:read("sell red_potion,steel to alpha")
print()
act:read("sell apple, red_potion to alpha")
act:read("sell apple , red_potion to alpha")
act:read("sell apple ,red_potion to alpha")
act:read("sell apple,red_potion to alpha")
print()
act:read("sell @ to alpha")
end
function love.update(dt)
end
function love.draw(dt)
end
Code: Select all
--lib.lua
local L = {}
local action = {}
local MT = {
__index = action
}
function L.connect()
local obj = { a = 1 }
return setmetatable(obj, MT)
end
function action.read(self, params)
local f = params
local command = f:match("^(%S*)")
f = string.sub(f, string.len(command)+2)
print(command, f)
if command == "sell" then
local col = {}
while f:match("(%S*)") ~= "to" do
col[#col+1] = f:match("(%S*)[%s,*]")
--col[#col+1] = f:match("(%w*)[%s,*]")
--col[#col+1] = f:match("([%w%s]*)[%s,*]")
f = string.sub(f, string.len(col[#col])+2)
print("item added")
end
for k,v in ipairs(col) do print(k, v) end
elseif command == "buy" then
end
end
L.action = action
return L
(also, this is a minimalist code with my logic problem for a library, so, another way to deal with this isn't an option, i need a string pattern)