Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettify function tostring #2870

Merged
merged 5 commits into from
Nov 22, 2023
Merged

Prettify function tostring #2870

merged 5 commits into from
Nov 22, 2023

Conversation

Denneisk
Copy link
Member

@Denneisk Denneisk commented Nov 17, 2023

Outputs function(ARGS): RET for tostring operations including printTable.

@Denneisk
Copy link
Member Author

Denneisk commented Nov 17, 2023

(Don't merge yet will also put E2Descriptions for functions since they weren't included)

Copy link
Contributor

@Vurv78 Vurv78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, forgot to update the tostring post making functions store their arguments and return types

@@ -76,6 +76,9 @@ end
---@field ret string
local Function = {}
Function.__index = Function
Function.__tostring = function(self)
return "function(" .. self.arg_sig .. ")" .. (self.ret and ": " .. self.ret or "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "function(" .. self.arg_sig .. ")" .. (self.ret and ": " .. self.ret or "")
return "function(" .. self.arg_sig .. ")" .. (self.ret and (": " .. self.ret)) or ""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the LuaLS upset

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need another set of parens wrapping or "" I assume

lua/entities/gmod_wire_expression2/core/e2lib.lua Outdated Show resolved Hide resolved
@Denneisk Denneisk changed the title Prettify function tostring Lambda Function Cleanups Nov 17, 2023
@Denneisk
Copy link
Member Author

Actually, should functions be allowed in arrays?

@@ -1868,7 +1868,9 @@ local CompileVisitors = {
---@type E2Lambda
local f = expr(state)

if f.arg_sig ~= sig then
if not f then
state:forceThrow("Trying to call function that doesn't exist!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the default function to one that throws this error. This is adding overhead to every function call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do that but then it gives an error for bad parameters instead, which I thought would be unideal.

let BadFunc = table()[1, function]

BadFunc(1) # Error: Expected void

If you think that's worth sacrificing, then that's fine. The error stems from the same root I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a compromise, maybe the error could be thrown after if f.arg_sig ~= sig? Then it would only be adding that overhead to errors. Compare it to a nofunction constant.

@Denneisk
Copy link
Member Author

Denneisk commented Nov 19, 2023

Forgot error throws an uncatchable error so I hope this is okay (it's just a convenience function for E2Lib.Debug.Error.New, not a method that uses self in a meaningful manner).

@Vurv78
Copy link
Contributor

Vurv78 commented Nov 19, 2023

Ok. I'm at my PC. Can we please not make completely different changes to a PR after already getting an accepting review (basically making it pointless?) Either leave it as draft or make another PR.

@Vurv78
Copy link
Contributor

Vurv78 commented Nov 19, 2023

At this point I'm just leaning toward not having a default value for function. It's pointless trying to accommodate old E2. Ideally @strict would do this but chances are that'd break 99% of strict chips. So seems it's time for that new versioning directive.

@Denneisk
Copy link
Member Author

Right, my bad.

@Denneisk Denneisk changed the title Lambda Function Cleanups Prettify function tostring Nov 22, 2023
@Denneisk Denneisk requested a review from Vurv78 November 22, 2023 07:52
@Vurv78 Vurv78 merged commit f2f87c5 into wiremod:master Nov 22, 2023
1 check failed
@Denneisk Denneisk deleted the function-str branch November 8, 2024 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants