🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Some questions regarding Lua

Started by
3 comments, last by Hazelnuss 20 years, 10 months ago
I am going to use Lua for scripting in my game but before i can actually start i need a few questions answered about which i am confused: - Can i use a Lua thread and let it run functions parallel to my game? I would use that for in-game movie sequences - What are the quitting conditions for a thread? Just errors and end-of-script or will it run until i terminate it? - How would i implement a Wait function for a thread? I studied the manual and some other threads in this forum but i couldn't find any answers.... thanks for any help. [EDIT] I am using Lua5 by the way. [edited by - Hazelnuss on August 23, 2003 5:55:14 AM]
Advertisement
You probably will want to look at coroutines.
Thus you can run scripts and have them suspend (coroutine.yield()). Using the parameters passed to and fro you can implement a wait-function.
It''s not exactly nice, but it works like a charm.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Okay, i will study on coroutines but i thought they were about the same as threads?

Hmm could i also use something like this as a Wait function?

void Wait(DWORD ms){    DWORD now = timeGetTime();    while((timeGetTime() - now) < ms);} 
Anybody knows why this won''t work?

C++
#pragma comment(lib, "lua.lib")#pragma comment(lib, "lualib.lib")extern "C"{#include <lua.h>#include <lualib.h>#include <lauxlib.h>}#include <iostream>#include <string>using namespace std;static int _wait(lua_State * L){	return lua_yield(L, 0);}void main(){	bool running = true;	lua_State * L = lua_open();	lua_baselibopen(L);	lua_register(L, "wait", _wait);	lua_State * Thread = lua_newthread(L);	lua_dofile(Thread, "test.txt");	do	{		string input;		cin >> input;		lua_resume(Thread, 0);		if(input == "exit")			running = false;	}while(running);	lua_close(L);} 


Lua
while true doprint("Hallo")wait()end 
Okay, after 10 hours experimenting i got it working. Thanks.

This topic is closed to new replies.

Advertisement