Closed JLPLabs closed 8 months ago
A PR is definitely welcome!
On Mon, Oct 30, 2023, 19:34 JLPLabs @.***> wrote:
The code below, using debug.getlocal([thread,] f, local), generates warnings and errors, despite using getlocal as specified in [1] (and all previous versions through and including 5.1). Quoting from [1], This function returns the name and the value of the local variable with index local of the function at level f of the stack.
-- getlocal.tl local name: string local val: string name, val = debug.getlocal(2, 1)
tl check generates...
tmp> tl check getlocal.tl
2 warnings: getlocal.tl:3:1: only 0 values are returned by the function getlocal.tl:3:7: only 0 values are returned by the function
3 errors: getlocal.tl:3:1: variable is not being assigned a value getlocal.tl:3:7: variable is not being assigned a value getlocal.tl:3:28: argument 1: got integer, expected function(...:
): ... getlocal is defined at line 5313 in tl.tl.
["getlocal"] = a_type { typename = "poly", types = { a_type { typename = "function", args = TUPLE { THREAD, FUNCTION, NUMBER }, rets = TUPLE {} }, a_type { typename = "function", args = TUPLE { FUNCTION, NUMBER }, rets = TUPLE {} }, }, },
Perhaps it is appropriate to insert another definition to types{} table, like this:
a_type { typename = "function", args = TUPLE { NUMBER, NUMBER }, rets = TUPLE { STRING, STRING } },
I'd be happy to do a pull request if that is your preference.
[1] Lua 5.4 Reference Manual; https://www.lua.org/manual/5.4/manual.html#pdf-debug.getlocal
— Reply to this email directly, view it on GitHub https://github.com/teal-language/tl/issues/713, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB365MQUKCYBOO6MKXU4XLYCATPJAVCNFSM6AAAAAA6WYFTK6VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE3DSMZSHE3DKNQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
it's weird that the other cases of the definition are also missing
rets
... Also, in the case you're adding, the rets tuple should probably
be something like STRING, ANY
?
(Replying via email from the phone, so sorry for any bad formatting!)
On Mon, Oct 30, 2023, 19:45 Hisham Muhammad @.***> wrote:
A PR is definitely welcome!
On Mon, Oct 30, 2023, 19:34 JLPLabs @.***> wrote:
The code below, using debug.getlocal([thread,] f, local), generates warnings and errors, despite using getlocal as specified in [1] (and all previous versions through and including 5.1). Quoting from [1], This function returns the name and the value of the local variable with index local of the function at level f of the stack.
-- getlocal.tl local name: string local val: string name, val = debug.getlocal(2, 1)
tl check generates...
tmp> tl check getlocal.tl
2 warnings: getlocal.tl:3:1: only 0 values are returned by the function getlocal.tl:3:7: only 0 values are returned by the function
3 errors: getlocal.tl:3:1: variable is not being assigned a value getlocal.tl:3:7: variable is not being assigned a value getlocal.tl:3:28: argument 1: got integer, expected function(...:
): ... getlocal is defined at line 5313 in tl.tl.
["getlocal"] = a_type { typename = "poly", types = { a_type { typename = "function", args = TUPLE { THREAD, FUNCTION, NUMBER }, rets = TUPLE {} }, a_type { typename = "function", args = TUPLE { FUNCTION, NUMBER }, rets = TUPLE {} }, }, },
Perhaps it is appropriate to insert another definition to types{} table, like this:
a_type { typename = "function", args = TUPLE { NUMBER, NUMBER }, rets = TUPLE { STRING, STRING } },
I'd be happy to do a pull request if that is your preference.
[1] Lua 5.4 Reference Manual; https://www.lua.org/manual/5.4/manual.html#pdf-debug.getlocal
— Reply to this email directly, view it on GitHub https://github.com/teal-language/tl/issues/713, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB365MQUKCYBOO6MKXU4XLYCATPJAVCNFSM6AAAAAA6WYFTK6VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE3DSMZSHE3DKNQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Will do. Good point about STRING, ANY.
to your point about the other cases needing 'rets'... I could do a PR for them such that the entire branch looks like this
types = {
a_type { typename = "function", args = TUPLE { THREAD, FUNCTION, NUMBER }, rets = STRING },
a_type { typename = "function", args = TUPLE { THREAD, NUMBER, NUMBER }, rets = TUPLE { STRING, ANY } },
a_type { typename = "function", args = TUPLE { FUNCTION, NUMBER }, rets = STRING },
a_type { typename = "function", args = TUPLE { NUMBER, NUMBER }, rets = TUPLE { STRING, ANY } },
},
NOTE: calling getlocal
with a function does NOT return a tuple, rather it returns a string holding the function arg, like this:
Lua 5.4.6 Copyright (C) 1994-2023 Lua.org, PUC-Rio
> function f1 (a, b) return a + b end
> f1(2, 40)
42
> debug.getlocal(f1,1)
a
> debug.getlocal(f1,2)
b
The code below, using
debug.getlocal([thread,] f, local)
, generates warnings and errors, despite usinggetlocal
as specified in [1] (and all previous versions through and including 5.1). Quoting from [1], This function returns the name and the value of the local variable with index local of the function at level f of the stack.tl check
generates...getlocal is defined at line 5313 in tl.tl.
Perhaps it is appropriate to insert another definition to types{} table, like this:
I'd be happy to do a pull request if that is your preference.
[1] Lua 5.4 Reference Manual; https://www.lua.org/manual/5.4/manual.html#pdf-debug.getlocal