Jump to content
  • Advertisement
Sign in to follow this  
Martin Perry

Lua - data persistance

This topic is 2020 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 have Lua script, that runs in every frame of simulation (eg. is restarted) and is called from C program.

 

I need to have some data persistent over time and change them from Lua script. How can I achieve this ? Persistent data are stored in table with certain name, so I can access this table from C application.

 

How can I store this table after script finish and restore it before it will run again ? Because with run again, values are set back to its default values.

 

Thank you

Share this post


Link to post
Share on other sites
Advertisement

Can't you just have the script return the table after it's done so you can store it in some variable in your c program. Then all you have to do is just pass the table back into the script next time you run it. 

Share this post


Link to post
Share on other sites

Yes.. that was my thought.. but how to get table with "unknown" content to C ? Serialization seems not so fast solution and lua_topointer is more for debugging

Share this post


Link to post
Share on other sites

Yes.. that was my thought.. but how to get table with "unknown" content to C ? Serialization seems not so fast solution and lua_topointer is more for debugging

A better question you could ask is why do you create the context again every frame and execute a file? You usually should create a context and load a file. After that you can call some (fixed) callback function every frame, this way the data is remembered.

Share this post


Link to post
Share on other sites

 

Yes.. that was my thought.. but how to get table with "unknown" content to C ? Serialization seems not so fast solution and lua_topointer is more for debugging

A better question you could ask is why do you create the context again every frame and execute a file? You usually should create a context and load a file. After that you can call some (fixed) callback function every frame, this way the data is remembered.

 

 

Well.. that is good point.. I didnt really thought about it that way... I will give it a try

Share this post


Link to post
Share on other sites

You could have a look at my lua script interface code, which get and set some globals strings, but you can use it for integer and boolean too. The python code is not very good but the lua one works 100%. I did stuffs that way since using stack parameters caused some strange bugs that only happened once randomly, but using a global instead solved the issue.

Edited by Vortez

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!