strong: Makes strings stronger (1.0.2)
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: strong: Makes strings stronger
Hey string.title() would be a good idea.
Yeah, I'll make them iterators.
Yeah, I'll make them iterators.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: strong: Makes strings stronger (1.0)
Alright everyone, 1.0 has been released. I'm currently writing the documentation in the wiki. Everything is now tested, and all 60 of them pass. Enjoy!
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: strong: Makes strings stronger (1.0.1)
I've just released 1.0.1. No changes to the API, just some stuff under-the-hood is better now. Check out the repo and the change log for more information.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: strong: Makes strings stronger (1.0.1)
I need your opinion guys. I want to add string interpolation, but I'd like some opinions on the style of how to do this. Firstly what syntax do you think is good. The two I have in mind is:
(Ruby syntax), or
(as seen in the reference manual). Being a Rubyist, I prefer the first out of those two of course.
Next is how to parse it. It'll need to be done by a method. My options here are:
1. When the call syntax is used with no arguments, it parse the string for interpolation.
2. A normal method, named run or something (suggestions on name?).
I tend to prefer the first, because it fits nicely with the syntax normally used with loadstring:
So what do you think?
Code: Select all
"#{i * 42}. Say hello."
Code: Select all
"$i * 42$. Say hello."
Next is how to parse it. It'll need to be done by a method. My options here are:
1. When the call syntax is used with no arguments, it parse the string for interpolation.
Code: Select all
("#{i * 42}. Say hello.")()
Code: Select all
("#{i * 42}. Say hello."):run() -- or
("#{i * 42}. Say hello."):parse()
Code: Select all
loadstring("foo = 3")()
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: strong: Makes strings stronger (1.0.1)
The first for string syntax, the Ruby way. In a templating utility function I wrote, I actually just used curly brackets, without anything before it, but that might not be very usable in this case.
I don't recommend the call syntax, because it's hardly self-documenting: there is no obvious meaning to calling a string. Furthermore, it might be easily missed when casually reading the source.
I don't recommend the call syntax, because it's hardly self-documenting: there is no obvious meaning to calling a string. Furthermore, it might be easily missed when casually reading the source.
Help us help you: attach a .love.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: strong: Makes strings stronger (1.0.1)
I'm not sure this function is needed, since Lua already has string.format, which does a very similar thing.
But if I were doing this, I'd try to use the % symbol, since it's the one used in that function. (It's also the symbol used in Python, btw).
Regarding the name, I'd call it "interpolate", or "parse". I'd not use the __call metamethod.
But if I were doing this, I'd try to use the % symbol, since it's the one used in that function. (It's also the symbol used in Python, btw).
Regarding the name, I'd call it "interpolate", or "parse". I'd not use the __call metamethod.
Code: Select all
string.parse("You have seen this page %{1} times")
-- would be more or less equivalent to
string.format("You have seen this page %d times", 1)
When I write def I mean function.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: strong: Makes strings stronger (1.0.1)
Except not really. This is more like SimpleLuaPreprocessor, except it is less powerful than the SLP.kikito wrote:I'm not sure this function is needed, since Lua already has string.format, which does a very similar thing.
Help us help you: attach a .love.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: strong: Makes strings stronger (1.0.1)
Hmmm, I like the call syntax though, because it's convenient; how does having both options sound? As in, __call would redirect to the method.
I would contest that there is an, at least somewhat, logical meaning to calling a string. Functions do, or run, code; calling the string would run code, just in different places and resulting in different things.
And yes, I like that %{} syntax.
EDIT: I'm not going to do interpolation. The trickery required to get locals to be usable is just not cool. It's not pretty, and it won't work without the debug library (SELOVE doesn't have this).
I would contest that there is an, at least somewhat, logical meaning to calling a string. Functions do, or run, code; calling the string would run code, just in different places and resulting in different things.
And yes, I like that %{} syntax.
EDIT: I'm not going to do interpolation. The trickery required to get locals to be usable is just not cool. It's not pretty, and it won't work without the debug library (SELOVE doesn't have this).
Last edited by BlackBulletIV on Sat May 14, 2011 9:43 am, edited 1 time in total.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: strong: Makes strings stronger (1.0.2)
Strong 1.0.2 has been released! We've got three new methods in this one, center, camelize, and underscore.
Is double posting in this situation correct, or not?
Is double posting in this situation correct, or not?
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: strong: Makes strings stronger (1.0.2)
I've added a video demonstration of some of the features to the main post.
Who is online
Users browsing this forum: No registered users and 70 guests