lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> gmatch_aux = string.gmatch("abc", ".")
> debug.getupvalue(gmatch_aux, 1)
        abc
> debug.getupvalue(gmatch_aux, 2)
        .
> debug.getupvalue(gmatch_aux, 3)
        0
> debug.setupvalue(gmatch_aux, 3, -100)

> gmatch_aux()

> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte())
0
> print(gmatch_aux():byte(1,-1))
191
> print(gmatch_aux():byte(1,-1))
62
> print(gmatch_aux():byte(1,-1))
110

Basically you can set gmatch_aux's 3rd upvalue to a negative number and it will read it even if it's not within the string.