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

Better print function #2691

Merged
merged 7 commits into from
Aug 12, 2023
Merged

Better print function #2691

merged 7 commits into from
Aug 12, 2023

Conversation

Vurv78
Copy link
Member

@Vurv78 Vurv78 commented Jul 26, 2023

  • Make print use net messages instead of ChatPrint, allowing longer print lengths
  • Added clientside convar wire_expression2_print_max_length (Default 1,000)
  • Added serverside convar wire_expression2_print_max_length (Default 10,000)
  • print now uses the e2 types (rather than lua type) of the argument to locate any toString methods for the type, if any are found, they will be used to display the value.
  • print now cuts off with E2Lib.limitString (which shows a trailing ... if it was cut off)
  • Created toString(r:) and toString(r), which show as array(1, 2, 3)
  • Change vector and angle's toString methods to return as the new print() format was (vec() / ang())
  • print no longer has a limit of 256 arguments (although nobody will ever make use of this)
  • print costs more ops the longer the combined string
print("Hi", vec(1, 2, 3), table("foo" = "bar"), array(1, "string", vec(), 4))
print(opcounter())

# "Hi"	vec(1.00,2.00,3.00)	foo	=	bar
# 	array(1, "string", vec(0.00,0.00,0.00), 4)
# 130

RFC:

  • Worth changing table's toString method to be streamlined with array, vec, ang? Code is really gross so I didn't want to mess with it.
  • Max print length fine? Higher? Lower?
  • Op costs fine? Higher? Lower?

Removed that 256 limit on number of arguments passed. I doubt anyone will go over it but that limit was pointless now that you can print more than 256 chars.

toString methods that are called now have their initial opcosts added upon being used inside print(...)

print(...) has base cost of 40 ops now.
To avoid ugly unquoted string, and default angle/vector output
@@ -414,7 +414,7 @@ e2function vector angle:up()
end

e2function string toString(angle a)
return ("[%s,%s,%s]"):format(a[1],a[2],a[3])
return ("ang(%d,%d,%d)"):format(a[1], a[2], a[3])
Copy link
Contributor

Choose a reason for hiding this comment

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

should be %f

e2function string toString(vector v)
return ("[%s,%s,%s]"):format(v[1],v[2],v[3])
return ("vec(%.2f,%.2f,%.2f)"):format(v[1], v[2], v[3])
Copy link
Contributor

Choose a reason for hiding this comment

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

Taking precision away might not be favorable

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a second argument to the function for a rounding decimal place?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thought two digits of precision was fine, if they want incredible precision they could just print the individual digits.
Alternatively could use %g.

And print already had this output, this is just replacing toString's output with it.

@Hazeofdream
Copy link
Contributor

Possible option to have a global print function?

@Vurv78
Copy link
Member Author

Vurv78 commented Jul 27, 2023

@Hazeofdream
Copy link
Contributor

Hazeofdream commented Jul 28, 2023

Need a rewritten version of https://github.com/Vurv78/VExtensions/blob/master/lua/entities/gmod_wire_expression2/core/custom/sv_printglobal.lua and would need to be opt-in

instead of opt-in because most people can't even edit an e2 line, what about a command similar to wire_holograms_block_client? and print globals show the user sending in console.

@Vurv78
Copy link
Member Author

Vurv78 commented Jul 28, 2023

Would absolutely need to be opt in serverside or would be so nerfed it would be practically unusable, with a long cooldown, preventing more than like 5 lines, adding [E2] before every message, etc

Clientside can be opt out yes

printDriver already has a disclaimer system for the first time it's used on a person so likely that would need to happen here too

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 2, 2023

I think it looks fine. I think this will still net overflow people if they print too much though.

@Vurv78
Copy link
Member Author

Vurv78 commented Aug 11, 2023

Assuming you're talking about the repo I linked and not this, considering the limit is only ~4x higher by default now

@thegrb93
Copy link
Contributor

I mean its not rate limited so doing a bunch of prints will overflow the buffer eventually.

@Vurv78
Copy link
Member Author

Vurv78 commented Aug 11, 2023

Prints do have a burst cooldown, can always tweak it a bit if needed

@thegrb93
Copy link
Contributor

Ah I forgot about the cooldown. Does the cooldown throw? I always hated that it made debugging confusing sometimes because it would fail to print due to it.

@Vurv78
Copy link
Member Author

Vurv78 commented Aug 11, 2023

Yeah I asked in the discord and iirc feedback was that it'd be really bad for debugging having to wrap everything in try catch.

Although with these larger limits it shouldn't be as common.

@Vurv78 Vurv78 merged commit 244828b into wiremod:master Aug 12, 2023
1 check failed
@Vurv78 Vurv78 deleted the better-print branch August 12, 2023 20:54
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.

3 participants