/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/libraries/lua/luascriptingengine.hpp

*/

#ifndef SGXLIB_LUA_SCRIPTING_MANAGER_HPP
#define SGXLIB_LUA_SCRIPTING_MANAGER_HPP	1

class CLuaScriptState : public CScriptState {
public:
	CLuaScriptState(CScriptingEngine *pEng);
	~CLuaScriptState();
	virtual	tBOOL	process(const sgxString &filename);
	virtual	tBOOL	reset();
	virtual	tBOOL	run();
	virtual	tBOOL	step();
	virtual	tBOOL	evaluate(const sgxString &code);

			tBOOL	doCall(int status);
			tBOOL	luaCall();
protected:
	virtual tBOOL	luaLoadScriptFile(const sgxString &filename);
	static const char *luaLoadGetBuffer(lua_State *, void *ud, size_t *size);

private:
	lua_State	*m_LState;
	sgxString	m_Filename;
	tBOOL		m_bLoaded;

	tBOOL luaReport(int status);
	tBOOL luaCall(int narg, int clear);

	friend class CLuaScriptingEngine;
};


class CLuaScriptingEngine : public CScriptingEngine {
public:
	static CLuaScriptingEngine	*create();

	virtual CScriptState	*initialise();
	virtual	tBOOL			openLibrary(CScriptState *pState, const sgxString &libname);
	virtual	tBOOL			openStandardLibraries(CScriptState *pState);
	
protected:
    static CLuaScriptingEngine  *ms_pSingleton;
};

#endif /* SGXLIB_LUA_SCRIPTING_MANAGER_HPP */
