Codea Chat Room

@JakAttak You can’t see before you logged on because the server clips everything to a maximum of five messages. It doesn’t store the previous chat cache because then it would look funny, seeing what you saw maybe a few hours ago right before the new text.

Hey, try to use a NoSQL database like MongoDB, it will be faster and cheaper in space :wink:

@juaxix, @SkyTheCoder

Or throw away the PHP/MySQL and roll your own little server in Lua using sockets for the network-y bits and tables for state.

PHP is a nightmare - one of the worst things to happen to coders since the dawn of dynamic content. MySQL is its counterpart. They’re both very popular, but, as far as I can work out, only because they’re free.

Given the relative simplicity of what you’re doing, it’d probably be cleaner, easier (once you’ve grokked a couple additional APIs), and, most of all, much more fun.

You guys already know Lua, so you’re already on your way. And everything you’d have to do server-side would only teach you more.

You could design your own simple protocol, which would save you from yet another evil (HTTP). You’d still have to deal with HTTP headers, but you could use that to your advantage.

And, I guarantee, if you do a good job of the protocol, you will have learned everything you need to learn in order to write a snazzy client-side command parser (right now you’re using gsub’s scattered throughout your code - all of that can be consolidated into a clean, centralized block of awesomeness).

What you’ve already done is harder than what you would have to do. Your project is a really impressive collection of square pegs fit into round holes (the nature of a chat application goes against everything that PHP and HTTP are about).

Also, it probably isn’t clear from my tone, but I’m complimenting you. You really have done something cool. Taking a collection of technologies that were meant to do something completely different from what you’re doing is the definition of “hack” (which is good).

If you want to get technical about it, the proper way to do it would be a compiled, typesafe language and an enterprise class database.

Personally, I’m fond of using CGI, rather than interpreted scripts. Yes, it’s an old model, but it’s perfect for what it’s designed for. I think they should entirely throw out the runtime interpreted script code and write the whole thing in C++. They should also buy an Enterprise license of Oracle or SQL Server to make sure that they get the performance and stability that they need.


Obviously there’s nothing wrong with using PHP, as long as you’re not a noob. No, PHP is not typsafe. Yes, you can do horrible, horrible things that would make any software engineer scream with pain and make the good folks over at shout with glee.

You can do the same with Lua. Self-modifying code? No problem. Pass a string into a method expecting an integer? Who needs all that pesky type checking anyway?

There are days I wish we could go back to MS BASIC running on 8-bit computers…


C++ for a simple, fun chat server is going in the wrong direction. So is tying it all to a heavy database.

Yes, you get type safety with C, but the number of disasters awaiting you down that route make it a bad choice.

And, yes, Lua also has a few gotchas that can lead to problems, but, again, this is about making a simple chat server for fun.

You can do a good job with either language and you can do a bad job with either language, but it’s fair to say you’re going to do a better job if you can focus on the meat of your app rather than trying to understand pointers and manual memory management (which is messy even when you have an implementation of C that helps you out, as is the case with Objective-C).

If you’re worried about injection in Lua, there are plenty of ways to safeguard your code. One is to fiddle with environments. Another is to round up the potential offenders (load*) and assign nil to them all. If you still need them for your own app, you can come up with identifiers of your own choosing (“loadrenamedhahnobodywillfindmehere”, for example) and then assign nil to the originals. Take your pick.

Even old school BASIC is more trouble in some ways. DEF SEG and VARPTR come to mind.

If, in the end, you still want C (for some reason), you can always code whatever bits you like in your preferred flavor of the language and then use Lua as it was originally intended: a library. That’s what the Lua interpreter does, and it’s also one of the reasons Lua is a good choice for coding directly on your iWhatever.

But the most important point really is: Fun. And that’s something Lua does very well.

You missed the . :slight_smile: everyone is bagging on Sky and Briarfox’s choice of scripting languages, when the truth of the matter is that these guys are turning out some excellent work, considering the limitations they are working under.

People saying stuff like “use a nosql database” or “use sockets, not http” are missing the point. These guys have a fairly limited set of tools to work with and are still doing good work. They should be cheered, not criticized because they didn’t use someone’s favorite database or language.

Agreed. They’re just having fun, and trying out stuff, not building the next Skype.

Now if they’d written it in TeX, I would have been impressed.

@Ignatz Funny, I was literally thinking about making a video chat program a few days ago…

This chat room will hopefully have some more features in the future including clickable links, pictures, emoticons, etc.

@Andrew_Stacey TeX?

2 things I’ve noticed with a Bluetooth keyboard:

  1. I still have to tap the text area to send a message. It would be nice if that’s always active when the keyboard is connected.
  2. Even with the BT keyboard, the text area still gets pushed halfway up the screen.

I’m guessing that #2 is caused by the fact that the runtime don’t have the API necessary to determine whether a BT keyboard is connected…

Also, is there a user list? It would be nice to know who’s logged in. =)

Wow! I still can’t believe that this nice piece of work was programmed by a 12 years old boy! :open_mouth:

Edit: I’m 3.7 times that age and still strugglig with table.insert!

@tomxp411 I’m going to add a “Bluetooth mode” switch that toggles the text field being pushed up when you are typing. Without it pushing up, using the soft keyboard, you can’t see what you’re typing. Sadly, there’s no way to automatically detect a BT keyboard. If I could, I would make it not be pushed up.

And I’ve chatted with people about a user list, but I’ve decided there’s too many problems with the idea. It could tell when someone logs on or off by the joining/leaving messages, but if say, someone crashes, it doesn’t send the message they left and still thinks they’re online.

@quezadav Summon the Nyan Cat and say “Bang!”

It would be interesting also to know at what time the people would chat, I mean, like a coffee break hour or something like that, hehe: socializing Codea.

Hmm… do the refresh requests include a user ID?

You could keep a “last updated” value for your users, and in the list function, silently drop users who haven’t refreshed the page for more than 1 minute.

Either way, I think you’re doing a great job. Keep it up. =)

@tomxp411 I could do that, but currently Briarfox is working on CC, and I don’t want to bug him.

@SkyTheCoder TeX is a programming language that is used primarily for typesetting documents. It was invented by Don Knuth (who you really ought to read about if you’re seriously interested in programming). It is wonderfully crafted for making it easy to type documents (particularly with mathematics) and therefore supremely ill-fitted for anything else. Therefore it would be a particularly impressive feat to program anything “normal” in TeX. Anyone who did something, say like a Mars rover, would be considered both barmy and amazing simultaneously.

So when anyone goes on about how something should be programmed in one language or another, I tend to drop in “How about TeX?” which soon makes everyone shut up.

@SkyTheCoder no problem. It is just something I noticed. =) Actually, if you aren’t against sharing the PHP code, I could take a crack at it. I haven’t had a chance to exercise my MAMP stack since I got my Mac.

Or if not, that’s no problem. I’ve certainly got enough to keep me busy… I just bought a book on iOS coding, so I’m going to be having some fun on this holiday weekend.

Nice work with the new scrolling! Although now it lets you pull past the bottom and top

@JakAttak I noticed that and I have no idea why it does that. I didn’t change anything there. Anyways, it just snaps back to place, so it’s no big deal.

I like to have my programs do exactly what I want without me having to explain in-depth, and to have it feel natural. Something that was bugging me was scrolling a tiny bit, letting go, and it moving. Now it doesn’t. But only when I don’t want it to. And I don’t have to say anything. It just knows.