🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Best way to implement Lua scripting

Started by
2 comments, last by Jedive 20 years, 2 months ago
I want to implement Lua as the scripting language for my engine, but the tutorials i have found about it only cover how to load and execute a script, and implementing scripts into a game engine goes further than that. I think that an appropiate way to integrate the scripts and the engine is to export the data type "entity" to the script. An entity would be anything that has a behaviour in the 3d scene. Each entity would have methods: OnCreate, OnUpdate, OnDestroy, etc. These would be called automatically bu the engine (when the entity is created, destroyed, or every time that the engine function Frame() is called by the scripts). Is this possible to do? The Frame() function then should get a pointer to the current execution point, to be able to restore it later, then loop through all the instances that are running of the "entity" class, and call their OnUpdate() functions. Then restore the previous execution point, so the script will continue running after the call to the Frame() function.
Advertisement
IMHO the best approach, as you said, is event driven scripting
in the last game I worked on I remember:
OnInit()OnTimer() //only if a timer was setOnContact(otherentity)OnDamage(damage)OnEvent(eventid,param) //generic event handler for 'custom' eventsOnShutdown()  

I suggest to not include a handler called every frame, is useless and
drive to bad practices; pure event driven is more elegant end efficient.
Also adding the builtin concept of state, to entities, with different sets
of handler for each state, was a winning choice.

ciao
Alberto

-----------------------------
The programming language Squirrel
http://squirrel.sourceforge.net

[edited by - fagiano on April 10, 2004 6:14:36 PM]
-----------------------------The programming language Squirrelhttp://www.squirrel-lang.org
Yay! That would be perfect! Do you know about a tutorial on how to implement a event-driven architecture to Lua?
It''s not really difficult. Use lua_call or resume if you use co-routines.

This topic is closed to new replies.

Advertisement