How does all this work? It works by being a repeat customer whom makes himself known to the management staff. It works by bringing friends, family, and co-workers to their place. It works by being nice, and fun, to the waitstaff. It works by being the type of customer whom seems to be having a great time so that when other patrons come in, they pick up the vibe and have a good time too.
Does all this imply work? sure, to some degree.... but I have to eat anyway, and I personally enjoy eating free. When I come in, the management staff recognize me on sight, call me by my name, and they come and chat with me for a few minutes. They deal with asshole customers all day, and here I come in and am a pleasure to deal with. The waitstaff, especially the new ones, notice the extra attention I'm getting from the management and they too pour on the niceties. The management often carries my food out and again chats with me. Many times there will be something extra on the plate, or some comment like, "we've got you covered today."
What do I talk with them about? Anything I would talk with a friend about if they worked there. I ask how business is going. I ask how their career is going. I ask if they've had any particularly hard customers. I ask if they are doing anything interesting on their day off. I ask how their family is doing. It is all very easy.
The folks whom work in restaurants bust their asses and deal with jerks while not making much money. It is quite easy to set yourself apart from the crowd by simply being nice and social to them. If you do this repeatedly at the same place, a place you particularly like, you will find all sorts of freebies thrown your way.