Sign in to follow this  
ionosphere

How to use Lua tables to manage resources efficiently?

Recommended Posts

ionosphere    122
Having resource path or a stage of a game in your source code is impractical and inflexible, so I wanted to tackle some scripting language. I just got my hand on Lua not so long ago, and I am thinking of mixing C++ +SDL+OpenGL with Lua. I have read about Lua and I am very interesting in using the table. However, I do not see the whole picture of how Lua and C++ can accomplish objectives together yet. For instances, which language should be responsible for what?, should C++ or Lua hold the pointers to the resources?, are there some design patterns to look for?, etc. Could you please provide me some guides or factors to consider? Thank you.

Share this post


Link to post
Share on other sites
ddn3    1610
The demarcation of responsibility between scripts and core code is arbitrary. You have to weight several factors to determine where the draw the line in how much responsibility/power you have to give the scripts vs how much you want to keep behind the engine.

Factors which affect this are:

1)performance
2)security
3)easy of use (convenience)
4)scalability

Every time you call into the core engine for something it has a time cost but keeping everything in scripts also has its own penalty as scripts are usually 5-50x slower than native code.

Scripts are usually exposed and allows designers to code the game from scratch. However you don't want anyone to wipe your hard drive or download malicious virus or execute buffer overrun attacks. So you'll have to be careful what functions you expose from the native interfaces and also to sandbox the scripts appropriately.

Easy of use, basically working within the paradigm of the scripting language. After writing for several scripting languages you'll see that they have some fundamental paradigms built into them about how to approach things. It's best to use the language as it was designed, this will have the least resistance.

Scalability is only really important if you plan on making large games/applications. Scripting is software engineering, so good planning and design in the early phase will pay off 100x over in the later stages. If your working as part of a team, it might be a good idea to build a script framework for them.

Good Luck!

-ddn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this