Jump to content

  • Log In with Google      Sign In   
  • Create Account


Lua - data persistance


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Martin Perry   Members   -  Reputation: 1247

Like
0Likes
Like

Posted 05 April 2014 - 07:37 AM

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



Sponsor:

#2 Ku134   Members   -  Reputation: 176

Like
0Likes
Like

Posted 05 April 2014 - 09:53 AM

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. 



#3 Martin Perry   Members   -  Reputation: 1247

Like
0Likes
Like

Posted 05 April 2014 - 10:22 AM

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



#4 ProtectedMode   Members   -  Reputation: 1107

Like
2Likes
Like

Posted 05 April 2014 - 11:21 AM

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.



#5 Martin Perry   Members   -  Reputation: 1247

Like
0Likes
Like

Posted 05 April 2014 - 11:37 AM

 

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



#6 Vortez   Crossbones+   -  Reputation: 2688

Like
0Likes
Like

Posted 05 April 2014 - 02:40 PM

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, 05 April 2014 - 02:40 PM.


#7 Martin Perry   Members   -  Reputation: 1247

Like
0Likes
Like

Posted 05 April 2014 - 02:55 PM

I solved it with tip from ProtectedMode. Thank you. Easy and elegant solution, that never crossed my mind






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS