• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

Ziphnor

Serializing a lua_State ?

8 posts in this topic

Im trying to plan how i will handle serialization(for saving / loading in my game), and all im missing is a neat way to store the state of the scripts running when saving. Im thinking it ought to be pretty simple, due to the stack based nature of lua. So what do i really need to do? I can write the stack itself to a file, and the just push everything back later when loading. But what more do i need to do(heap/instruction pointer perhaps)? Ive tried googling for this, but havent really come up with anything. Anyone have any experience with this? PS: im not using threads at all, the lua scripts runs and control returns to the C side when the script is finished, so none of the scripts will be running when script is to be saved from the native side. I assume this should makes things easier, serialization wise. Similar, the scripts dont have any type of pointers into the C side, they are only aware of some object handles, which will be the same when the game is restored. [edited by - ziphnor on May 13, 2003 6:19:42 PM] [edited by - ziphnor on May 13, 2003 6:28:30 PM]
0

Share this post


Link to post
Share on other sites
Thanks, but i already found that one, i also found this http://lua-users.org/lists/lua-l/2003-04/msg00339.html which, is a more general(ie harder) version of my problem, but no real solution is given.
I suppose i could check the source code for the lua_State and find out how its structured, but it seems likely that someone has already described this...
With my limited understanding of virtual stack machines it seems to me that simply storing the stack values(and possibly the heap, hell i dont even know if lua uses a heap? should be enough, if all the compiled code is also loaded again at load time. I mean im not trying to save it while its running so actually the instruction pointer etc. shouldnt be needed. Perhaps im missing something

[edited by - ziphnor on May 14, 2003 12:23:07 PM]
0

Share this post


Link to post
Share on other sites
Did you post your question on the Lua mailing list? I would be interested to follow that discussion.
0

Share this post


Link to post
Share on other sites
Something tells me that i should probably research it a bit more myself. 5 minutes with the reference manual, and i realized i misunderstood how lua handles global variables for example. Apparently they are stored in a seperate table etc.
But when ive read the material a bit more thoroughly you can be sure that ill try asking
0

Share this post


Link to post
Share on other sites
Since your Lua scripts are not threaded, why would you need to save the stack? The stack should be empty when the script returns. Barring return variables that is.

Saving the states of the global variables I can understand.

[edited by - LordShade on May 14, 2003 2:59:02 PM]
0

Share this post


Link to post
Share on other sites
Yeah, sorry about that, i thought the globals etc was stored on the stack(due to how we handled globals in a micro-C language in a compiler course i had , my mistake.

So perhaps i could just walk through the global table, saving everything i meet recursively(thus including other tables etc) except for functions. Then when loading i first load the code chunk(s) again, and then restore the tables, i suppose that should work, shouldnt it? The only question is whether or not this correctly restores the functions(that is the function code+their enviroment).

[edited by - ziphnor on May 14, 2003 4:04:41 PM]
0

Share this post


Link to post
Share on other sites
You could organize it so that the data is separate from the program, and then just go through and store all the data.

All the functions would be loaded from a file when your program starts, and then loading a saved game would just set all the data to the saved values.

Going through and saving everything that isn''t a function sounds like it could work. Really you just need to figure out what needs saving.
0

Share this post


Link to post
Share on other sites
I tried a simple scenario where i ran a simple lua file stored all the global numbers and strings (name and values) in some vectors. Then i closed the lua_State, opened a new one reloaded the lua file and libs, and the reinserted the values. After that i ran another small lua script that tested the values/functions in the previous one, it worked fine. But again, this is such a simple situation, its much more interesting what happens with things like:

local counter = 0
function inc() counter++ end

According to normal lua standards(5.0) the counter can be accessed by the function but its not part of any table etc reachable from the global table. Perhaps its contained in the function( or should i say function closure) or something like that? I wish knew more about lua

EDIT: I just noticed that its possible to retrieve a table giving the enviroment of the function using:
void lua_getfenv (lua_State *L, int index);
int lua_setfenv (lua_State *L, int index);
With this it should be possible to properly store the state of functions, since we can now serialize their entire local enviroment.

[edited by - ziphnor on May 15, 2003 3:52:27 PM]
0

Share this post


Link to post
Share on other sites