Moved Lua API registering into a separate function.
This will allow us to use Lua as lite-config files as well, should we want to.
This commit is contained in:
parent
392fb7923b
commit
0c15fdf7b0
@ -94,12 +94,20 @@ void cLuaState::Create(void)
|
|||||||
}
|
}
|
||||||
m_LuaState = lua_open();
|
m_LuaState = lua_open();
|
||||||
luaL_openlibs(m_LuaState);
|
luaL_openlibs(m_LuaState);
|
||||||
|
m_IsOwned = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cLuaState::RegisterAPILibs(void)
|
||||||
|
{
|
||||||
tolua_AllToLua_open(m_LuaState);
|
tolua_AllToLua_open(m_LuaState);
|
||||||
ManualBindings::Bind(m_LuaState);
|
ManualBindings::Bind(m_LuaState);
|
||||||
DeprecatedBindings::Bind(m_LuaState);
|
DeprecatedBindings::Bind(m_LuaState);
|
||||||
luaopen_lsqlite3(m_LuaState);
|
luaopen_lsqlite3(m_LuaState);
|
||||||
luaopen_lxp(m_LuaState);
|
luaopen_lxp(m_LuaState);
|
||||||
m_IsOwned = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,9 +139,14 @@ public:
|
|||||||
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
|
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
|
||||||
operator lua_State * (void) { return m_LuaState; }
|
operator lua_State * (void) { return m_LuaState; }
|
||||||
|
|
||||||
/** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor */
|
/** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor.
|
||||||
|
The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as
|
||||||
|
lite-config as well), use RegisterAPILibs() to do that. */
|
||||||
void Create(void);
|
void Create(void);
|
||||||
|
|
||||||
|
/** Registers all the API libraries that MCS provides into m_LuaState. */
|
||||||
|
void RegisterAPILibs(void);
|
||||||
|
|
||||||
/** Closes the m_LuaState, if not closed already */
|
/** Closes the m_LuaState, if not closed already */
|
||||||
void Close(void);
|
void Close(void);
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ bool cPluginLua::Initialize(void)
|
|||||||
if (!m_LuaState.IsValid())
|
if (!m_LuaState.IsValid())
|
||||||
{
|
{
|
||||||
m_LuaState.Create();
|
m_LuaState.Create();
|
||||||
|
m_LuaState.RegisterAPILibs();
|
||||||
|
|
||||||
// Inject the identification global variables into the state:
|
// Inject the identification global variables into the state:
|
||||||
lua_pushlightuserdata(m_LuaState, this);
|
lua_pushlightuserdata(m_LuaState, this);
|
||||||
|
@ -127,6 +127,7 @@ bool cWebAdmin::Start(void)
|
|||||||
|
|
||||||
// Initialize the WebAdmin template script and load the file
|
// Initialize the WebAdmin template script and load the file
|
||||||
m_TemplateScript.Create();
|
m_TemplateScript.Create();
|
||||||
|
m_TemplateScript.RegisterAPILibs();
|
||||||
if (!m_TemplateScript.LoadFile(FILE_IO_PREFIX "webadmin/template.lua"))
|
if (!m_TemplateScript.LoadFile(FILE_IO_PREFIX "webadmin/template.lua"))
|
||||||
{
|
{
|
||||||
LOGWARN("Could not load WebAdmin template \"%s\", using default template.", FILE_IO_PREFIX "webadmin/template.lua");
|
LOGWARN("Could not load WebAdmin template \"%s\", using default template.", FILE_IO_PREFIX "webadmin/template.lua");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user