#ifndef _luainterface_h
#define _luainterface_h

#include "empire.h"

extern void empdebug(string text);

class lua_state
{
public:
	static lua_State *get_instance()
	{
		static lua_state ls;
		
		if (ls.L == 0)
		{
			ls.L = luaL_newstate();
					
			if (ls.L == 0)
			{
				empdebug("Error creating Lua state");
				return 0;
			}
			
			luaL_openlibs(ls.L);
			
			if (luaL_dofile(ls.L, "scripts/gamesaves.lua"))
			{
				stringstream s;
				s << "Error loading script 'scripts/gamesaves.lua': " << lua_tostring(ls.L, -1);
				empdebug(s.str());
				return 0;
			}
		}
		
		return ls.L;
	}
	
private:
	lua_State *L;
	
	lua_state() : L(0)
	{}
	
	~lua_state()
	{
		if (L != 0)
			lua_close(L);
	}
	
	lua_state(const lua_state &s);
	lua_state &operator=(const lua_state &s);
};

#endif
