2013-07-28 20:37:59 -04:00
|
|
|
|
2013-07-29 04:03:42 -04:00
|
|
|
// LuaScript.cpp
|
|
|
|
|
|
|
|
// Implements the cLuaScript class that loads a Lua script file to produce a web template out of it
|
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "LuaScript.h"
|
|
|
|
#include "tolua++.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cLuaScript::cLuaScript()
|
2013-08-06 13:28:09 -04:00
|
|
|
: m_LuaState("cLuaScript")
|
2013-07-28 20:37:59 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cLuaScript::Initialize()
|
|
|
|
{
|
|
|
|
// Check to see if this script has not been initialized before
|
2013-08-06 13:28:09 -04:00
|
|
|
ASSERT(!m_LuaState.IsValid());
|
2013-07-28 20:37:59 -04:00
|
|
|
|
|
|
|
// Create a Lua state and bind all libraries to it
|
2013-08-06 13:28:09 -04:00
|
|
|
m_LuaState.Create();
|
2013-07-28 20:37:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-06 13:28:09 -04:00
|
|
|
bool cLuaScript::LoadFile(const char * a_FilePath)
|
2013-07-28 20:37:59 -04:00
|
|
|
{
|
|
|
|
// Make sure the plugin is initialized
|
2013-08-06 13:28:09 -04:00
|
|
|
ASSERT(m_LuaState.IsValid());
|
2013-07-28 20:37:59 -04:00
|
|
|
|
2013-08-06 13:28:09 -04:00
|
|
|
return m_LuaState.LoadFile(a_FilePath);
|
2013-07-28 20:37:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-06 13:28:09 -04:00
|
|
|
bool cLuaScript::CallShowPage(cWebAdmin & a_WebAdmin, HTTPTemplateRequest & a_Request, AString & a_ReturnedString)
|
2013-07-28 20:37:59 -04:00
|
|
|
{
|
2013-08-06 13:28:09 -04:00
|
|
|
ASSERT(m_LuaState.IsValid());
|
|
|
|
|
|
|
|
m_LuaState.PushFunction("ShowPage");
|
|
|
|
m_LuaState.PushUserType(&a_WebAdmin, "cWebAdmin");
|
|
|
|
m_LuaState.PushUserType(&a_Request, "HTTPTemplateRequest");
|
|
|
|
if (!m_LuaState.CallFunction(1))
|
2013-07-28 20:37:59 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (lua_isstring(m_LuaState, -1))
|
|
|
|
{
|
2013-08-06 13:28:09 -04:00
|
|
|
a_ReturnedString.assign(tolua_tostring(m_LuaState, -1, ""));
|
2013-07-28 20:37:59 -04:00
|
|
|
}
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|