Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] Lua in PHP?

Started by Mattman Nov 7, 2007 at 12:15 AM 6 replies 4.7k views
Original Post
Mattman
Mattman
I'm trying to find out if there's an easy way to implement Lua in PHP. Google is useless for searching anything like "Lua in PHP", as the results are just generic "Lua" located at sites/pages ending in ".php". If anyone can point me in the right direction, I'd greatly appreciate it. I'm also open to alternative methods you might have for implementing quests into a web-based RPG. :)
DvDmanDT
DvDmanDT
Umm.. I'm pretty sure there was a project to allow Lua scripts to be called from PHP or something like that, but why not just use PHP for the quests as well?
ID Merlin
ID Merlin
That's what I'd do. PHP has an eval function that you can use to run the scripts.
Mattman
Mattman
Thanks guys. I was thinking about the eval function too, but I wasn't sure what I wanted to do.

Would it be considered poor practice to include PHP scripts for quests in database records? My reasoning is that quest scripts reference item data, spell data etc...these pieces of data have auto-generated ID's, and I don't want to hack anything data-specific into my code.

I suppose I could create specific scripts like "leave_room_###.php" that I could then include() or require() into the currently running script, but I don't really like that option since it still feels like a hack to include data-specific code with app-centric code.

Just wondering what you guys would recommend in this regards. Hope my questions makes sense. :P Thanks again!
Sander
Sander
Quote:
Just wondering what you guys would recommend in this regards.


I'd recommend a decent plugin system of some kind instead of data-specific eval'ed code. The system you're discussing sounds like a maintenance nightmare to happen.
ID Merlin
ID Merlin
Scripts can be considered data like anything else. In my current project, I've built a script system that uses a "mini" programming language, with actions that are converted directly to PHP and evaled. The variables that can be used correspond directly to game values. For instance, a valid command would be to SET the PLAYER MORALE to 50. Or, ADD ITEM '+1 Sword' TO ENEMY.

If you are careful with your design, it should be maintainable. Build a good editor that validates the data, and you should be able to keep this under control.
Mattman
Mattman
Quote:
Original post by Sander
Quote:
Just wondering what you guys would recommend in this regards.


I'd recommend a decent plugin system of some kind instead of data-specific eval'ed code. The system you're discussing sounds like a maintenance nightmare to happen.

Do you have any recommendations, or could you point me in the right direction of a tutorial or something? I've never utilized plug-ins in my applications before.

All the solutions I could think of seemed like maintenance nightmares, which is why I came here. Thanks for the help :)
Mattman
Mattman
Quote:
Original post by ID Merlin
Scripts can be considered data like anything else. In my current project, I've built a script system that uses a "mini" programming language, with actions that are converted directly to PHP and evaled. The variables that can be used correspond directly to game values. For instance, a valid command would be to SET the PLAYER MORALE to 50. Or, ADD ITEM '+1 Sword' TO ENEMY.

If you are careful with your design, it should be maintainable. Build a good editor that validates the data, and you should be able to keep this under control.

Thanks Merlin, I was thinking of something along these lines as a possibility. I built a script parser/interpreter a good 7 years or so ago, and I was thinking about revamping it for this project. Appreciate the input! :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.