You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is this closed issue related to string.gmatch: #43
I would guess that the trickiness of implementing this is the stateful iterator gmatch should return.
Erl_func can't have mutable variables.
However, in Lua a table can be called as well, when it has a __call in its metatable.
So I found a way to implement gmatch in Lua itself:
string.gmatch=function(str, pattern)
localcallable= {
nextPos=0,
str=str,
pattern=pattern
}
localmt= {}
functionmt.__call(table)
match_start, match_end=string.find(table.str, table.pattern, table.nextPos)
if(match_start==nil) thenreturnnil;
elsetable.nextPos=match_end+1;
returnstring.sub(table.str, match_start, match_end)
endendsetmetatable(callable, mt)
returncallableendforwordinstring.gmatch("The big {brown} fox jumped {over} the lazy {dog}.","{(.-)}") doprint(word) end
It looks quite possible to implement this in luerl, since all we need to be able to do is in the erl_func:
get/set a value in a table
string find/sub (which are already implemented)
Would it make sense to implement is like this?
The text was updated successfully, but these errors were encountered:
@markmeeus I am slowly getting around to looking through old stuff. It would be nice to do it in erlang. I checked pairs and ipairs but they return a function to get the next pair. Must think a bit about this.
There is this closed issue related to string.gmatch:
#43
I would guess that the trickiness of implementing this is the stateful iterator gmatch should return.
Erl_func can't have mutable variables.
However, in Lua a table can be called as well, when it has a __call in its metatable.
So I found a way to implement gmatch in Lua itself:
It looks quite possible to implement this in luerl, since all we need to be able to do is in the erl_func:
Would it make sense to implement is like this?
The text was updated successfully, but these errors were encountered: