All pastes #620112 Raw Edit

Stuff

public cpp v1 · immutable
·published 2007-07-15 07:21 UTC
rendered paste body
void killLoop(lua_State* L) //Calling this kills the doThink loop and ends the program.{	lua_pushboolean(L,0); //push false	lua_setglobal(L,"Run"); // 'Run' = false (the top stack value)	//setglobal pop's for us, (DON'T POP AN EMPTY STACK OR YOU GET WEEE CRASH)}const char* getError(lua_State* Q){	const char* err = "";	if (lua_isstring(Q,-1)) //if we have a string(here an error)	{		err = lua_tostring(Q,-1);		lua_pop(Q,1);	}	return err;}void printError(lua_State* L,const char* str){	const char* err = getError(L);	printf("%s %s\n",str,err);	killLoop(L);	}void printError(lua_State* L,const char* str,int safe){	const char* err = getError(L);	printf("%s %s\n",str,err);	if (!safe)	{		killLoop(L);	}}int dostring(lua_State* L,const char* str){	if (luaL_loadstring(L,str))	{		printError(L,"Error during parse\n ->");		return 1; //BAAAAD	}	if (lua_pcall(L,0,0,0)) {		printError(L,"Runtime Error!\n-> ");		return 1; //BAAAAD	}	return 0; //All good}int dofile(lua_State* L,const char* str){	if (luaL_loadfile(L,str) != 0)	{		printError(L,"Error during parse\n ->");		return 1; //BAAAAD	}	if (lua_pcall(L,0,0,0)) {		printError(L,"Runtime Error!\n-> ");		return 1; //BAAAAD	}	return 0; //All good}#include <lua_funcs.h>