strong: Makes strings stronger (1.0.2)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: strong: Makes strings stronger

Post by BlackBulletIV »

Hey string.title() would be a good idea.

Yeah, I'll make them iterators.
User avatar
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)

Post by BlackBulletIV »

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!
User avatar
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)

Post by BlackBulletIV »

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.
User avatar
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)

Post by BlackBulletIV »

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:

Code: Select all

"#{i * 42}. Say hello."
(Ruby syntax), or

Code: Select all

"$i * 42$. Say hello."
(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.

Code: Select all

("#{i * 42}. Say hello.")()
2. A normal method, named run or something (suggestions on name?).

Code: Select all

("#{i * 42}. Say hello."):run() -- or
("#{i * 42}. Say hello."):parse()
I tend to prefer the first, because it fits nicely with the syntax normally used with loadstring:

Code: Select all

loadstring("foo = 3")()
So what do you think?
User avatar
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)

Post by Robin »

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.
Help us help you: attach a .love.
User avatar
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)

Post by kikito »

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.

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.
User avatar
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)

Post by Robin »

kikito wrote:I'm not sure this function is needed, since Lua already has string.format, which does a very similar thing.
Except not really. This is more like SimpleLuaPreprocessor, except it is less powerful than the SLP.
Help us help you: attach a .love.
User avatar
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)

Post by BlackBulletIV »

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).
Last edited by BlackBulletIV on Sat May 14, 2011 9:43 am, edited 1 time in total.
User avatar
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)

Post by BlackBulletIV »

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?
User avatar
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)

Post by BlackBulletIV »

I've added a video demonstration of some of the features to the main post.
Post Reply

Who is online

Users browsing this forum: No registered users and 70 guests