Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Best way to implement Lua scripting

This topic is 5330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
IMHO the best approach, as you said, is event driven scripting
in the last game I worked on I remember:

OnTimer() //only if a timer was set
OnEvent(eventid,param) //generic event handler for 'custom' events

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.


The programming language Squirrel

[edited by - fagiano on April 10, 2004 6:14:36 PM]

Share this post

Link to post
Share on other sites
Yay! That would be perfect! Do you know about a tutorial on how to implement a event-driven architecture to Lua?

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
It''s not really difficult. Use lua_call or resume if you use co-routines.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!