|
|
@ -1,38 +1,14 @@
|
|
|
|
/* The MIT License
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
|
|
* THE SOFTWARE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <global.h>
|
|
|
|
#include <global.h>
|
|
|
|
#include <script/luascript.h>
|
|
|
|
#include <script/scriptcontext.h>
|
|
|
|
#include <script/luafunctions.h>
|
|
|
|
#include <script/scriptfunctions.h>
|
|
|
|
#include <core/resources.h>
|
|
|
|
#include <core/resources.h>
|
|
|
|
#include <lua.hpp>
|
|
|
|
#include <lua.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
LuaScript g_lua;
|
|
|
|
ScriptContext g_lua;
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::init()
|
|
|
|
void ScriptContext::init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
L = luaL_newstate();
|
|
|
|
L = luaL_newstate();
|
|
|
|
if(!L)
|
|
|
|
if(!L)
|
|
|
@ -44,17 +20,17 @@ void LuaScript::init()
|
|
|
|
// setup custom package loader
|
|
|
|
// setup custom package loader
|
|
|
|
setupPackageLoader();
|
|
|
|
setupPackageLoader();
|
|
|
|
|
|
|
|
|
|
|
|
registerLuaFunctions();
|
|
|
|
registerScriptFunctions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::terminate()
|
|
|
|
void ScriptContext::terminate()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
collectGarbage();
|
|
|
|
collectGarbage();
|
|
|
|
lua_close(L);
|
|
|
|
lua_close(L);
|
|
|
|
L = NULL;
|
|
|
|
L = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::loadAllModules()
|
|
|
|
void ScriptContext::loadAllModules()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::list<std::string> modules = g_resources.listDirectoryFiles("modules");
|
|
|
|
std::list<std::string> modules = g_resources.listDirectoryFiles("modules");
|
|
|
|
foreach(const std::string& module, modules) {
|
|
|
|
foreach(const std::string& module, modules) {
|
|
|
@ -66,7 +42,7 @@ void LuaScript::loadAllModules()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::loadFile(const std::string& fileName)
|
|
|
|
bool ScriptContext::loadFile(const std::string& fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::stringstream fin;
|
|
|
|
std::stringstream fin;
|
|
|
|
if(g_resources.loadFile(fileName, fin))
|
|
|
|
if(g_resources.loadFile(fileName, fin))
|
|
|
@ -76,14 +52,14 @@ bool LuaScript::loadFile(const std::string& fileName)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::loadBuffer(const std::string& text, const std::string& what)
|
|
|
|
bool ScriptContext::loadBuffer(const std::string& text, const std::string& what)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(loadBufferAsFunction(text, what) && callFunction())
|
|
|
|
if(loadBufferAsFunction(text, what) && callFunction())
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::loadBufferAsFunction(const std::string& text, const std::string& what)
|
|
|
|
bool ScriptContext::loadBufferAsFunction(const std::string& text, const std::string& what)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = luaL_loadbuffer(L, text.c_str(), text.length(), ("@" + what).c_str());
|
|
|
|
int ret = luaL_loadbuffer(L, text.c_str(), text.length(), ("@" + what).c_str());
|
|
|
|
if(ret != 0){
|
|
|
|
if(ret != 0){
|
|
|
@ -98,7 +74,7 @@ bool LuaScript::loadBufferAsFunction(const std::string& text, const std::string&
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::reportError(const std::string& errorDesc, const char *funcName)
|
|
|
|
void ScriptContext::reportError(const std::string& errorDesc, const char *funcName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "LUA Script ERROR: ";
|
|
|
|
ss << "LUA Script ERROR: ";
|
|
|
@ -108,73 +84,73 @@ void LuaScript::reportError(const std::string& errorDesc, const char *funcName)
|
|
|
|
error(ss.str());
|
|
|
|
error(ss.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::reportErrorWithTraceback(const std::string& errorDesc, const char* funcName)
|
|
|
|
void ScriptContext::reportErrorWithTraceback(const std::string& errorDesc, const char* funcName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushString(errorDesc);
|
|
|
|
pushString(errorDesc);
|
|
|
|
luaErrorHandler(L);
|
|
|
|
luaErrorHandler(L);
|
|
|
|
reportError(popString(), funcName);
|
|
|
|
reportError(popString(), funcName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::collectGarbage()
|
|
|
|
void ScriptContext::collectGarbage()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(int i=0;i<2;i++)
|
|
|
|
for(int i=0;i<2;i++)
|
|
|
|
lua_gc(L, LUA_GCCOLLECT, 0);
|
|
|
|
lua_gc(L, LUA_GCCOLLECT, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::getStackSize()
|
|
|
|
int ScriptContext::getStackSize()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_gettop(L);
|
|
|
|
return lua_gettop(L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::insert(int index)
|
|
|
|
void ScriptContext::insert(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(index != -1)
|
|
|
|
if(index != -1)
|
|
|
|
lua_insert(L, index);
|
|
|
|
lua_insert(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::swap(int index)
|
|
|
|
void ScriptContext::swap(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
insert(index);
|
|
|
|
insert(index);
|
|
|
|
pushValue(index+1);
|
|
|
|
pushValue(index+1);
|
|
|
|
remove(index);
|
|
|
|
remove(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::remove(int index)
|
|
|
|
void ScriptContext::remove(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_remove(L, index);
|
|
|
|
lua_remove(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::next(int index)
|
|
|
|
bool ScriptContext::next(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_next(L, index);
|
|
|
|
return lua_next(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::releaseRef(int ref)
|
|
|
|
void ScriptContext::releaseRef(int ref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::newTable()
|
|
|
|
void ScriptContext::newTable()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_newtable(L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::setTable(int index)
|
|
|
|
void ScriptContext::setTable(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_settable(L, index);
|
|
|
|
lua_settable(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *LuaScript::newUserdata(int size)
|
|
|
|
void *ScriptContext::newUserdata(int size)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_newuserdata(L, size);
|
|
|
|
return lua_newuserdata(L, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::newMetatable(const std::string& name)
|
|
|
|
void ScriptContext::newMetatable(const std::string& name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
luaL_newmetatable(L, name.c_str());
|
|
|
|
luaL_newmetatable(L, name.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::setMetatable(const std::string& name, int index)
|
|
|
|
void ScriptContext::setMetatable(const std::string& name, int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
luaL_getmetatable(L, name.c_str());
|
|
|
|
luaL_getmetatable(L, name.c_str());
|
|
|
|
if(isNil())
|
|
|
|
if(isNil())
|
|
|
@ -183,57 +159,57 @@ void LuaScript::setMetatable(const std::string& name, int index)
|
|
|
|
lua_setmetatable(L, index < 0 ? index-1 : index);
|
|
|
|
lua_setmetatable(L, index < 0 ? index-1 : index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::rawGet(const std::string& key)
|
|
|
|
void ScriptContext::rawGet(const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushString(key);
|
|
|
|
pushString(key);
|
|
|
|
lua_rawget(L, -2);
|
|
|
|
lua_rawget(L, -2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::rawSet(const std::string& key)
|
|
|
|
void ScriptContext::rawSet(const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushString(key);
|
|
|
|
pushString(key);
|
|
|
|
insert(-2);
|
|
|
|
insert(-2);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::getField(const std::string& key)
|
|
|
|
void ScriptContext::getField(const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_getfield(L, -1, key.c_str());
|
|
|
|
lua_getfield(L, -1, key.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::setField(const std::string& key)
|
|
|
|
void ScriptContext::setField(const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_setfield(L, -2, key.c_str());
|
|
|
|
lua_setfield(L, -2, key.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::getScriptableField(const ScriptablePtr& scriptable, const std::string& field)
|
|
|
|
void ScriptContext::getScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(scriptable) {
|
|
|
|
if(scriptobject) {
|
|
|
|
pushRef(scriptable->getLuaTableRef());
|
|
|
|
pushRef(scriptobject->getScriptTable());
|
|
|
|
getField(field);
|
|
|
|
getField(field);
|
|
|
|
remove(-2);
|
|
|
|
remove(-2);
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
pushNil();
|
|
|
|
pushNil();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::setScriptableField(const ScriptablePtr& scriptable, const std::string& field)
|
|
|
|
void ScriptContext::setScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(scriptable) {
|
|
|
|
if(scriptobject) {
|
|
|
|
pushRef(scriptable->getLuaTableRef());
|
|
|
|
pushRef(scriptobject->getScriptTable());
|
|
|
|
insert(-2);
|
|
|
|
insert(-2);
|
|
|
|
setField(field);
|
|
|
|
setField(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pop();
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::rawGetGlobalTableField(const std::string& globalTable, const std::string& key)
|
|
|
|
void ScriptContext::rawGetGlobalTableField(const std::string& globalTable, const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
getGlobal(globalTable);
|
|
|
|
getGlobal(globalTable);
|
|
|
|
rawGet(key);
|
|
|
|
rawGet(key);
|
|
|
|
remove(-2);
|
|
|
|
remove(-2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::rawSetGlobalTableField(const std::string& globalTable, const std::string& key)
|
|
|
|
void ScriptContext::rawSetGlobalTableField(const std::string& globalTable, const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
getGlobal(globalTable);
|
|
|
|
getGlobal(globalTable);
|
|
|
|
insert(-2);
|
|
|
|
insert(-2);
|
|
|
@ -241,81 +217,81 @@ void LuaScript::rawSetGlobalTableField(const std::string& globalTable, const std
|
|
|
|
pop();
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::getGlobal(const std::string& key)
|
|
|
|
void ScriptContext::getGlobal(const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, key.c_str());
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, key.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::setGlobal(const std::string& key)
|
|
|
|
void ScriptContext::setGlobal(const std::string& key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_setfield(L, LUA_GLOBALSINDEX, key.c_str());
|
|
|
|
lua_setfield(L, LUA_GLOBALSINDEX, key.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isNil(int index)
|
|
|
|
bool ScriptContext::isNil(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_isnil(L, index);
|
|
|
|
return lua_isnil(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isBoolean(int index)
|
|
|
|
bool ScriptContext::isBoolean(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_isboolean(L, index);
|
|
|
|
return lua_isboolean(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isNumber(int index)
|
|
|
|
bool ScriptContext::isNumber(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_isnumber(L, index);
|
|
|
|
return lua_isnumber(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isString(int index)
|
|
|
|
bool ScriptContext::isString(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_isstring(L, index);
|
|
|
|
return lua_isstring(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isTable(int index)
|
|
|
|
bool ScriptContext::isTable(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_istable(L, index);
|
|
|
|
return lua_istable(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isUserdata(int index)
|
|
|
|
bool ScriptContext::isUserdata(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_isuserdata(L, index);
|
|
|
|
return lua_isuserdata(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isFunction(int index)
|
|
|
|
bool ScriptContext::isFunction(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_isfunction(L, index);
|
|
|
|
return lua_isfunction(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isCFunction(int index)
|
|
|
|
bool ScriptContext::isCFunction(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lua_iscfunction(L, index);
|
|
|
|
return lua_iscfunction(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::isLuaFunction(int index)
|
|
|
|
bool ScriptContext::isLuaFunction(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return isFunction(index) && !isCFunction(index);
|
|
|
|
return isFunction(index) && !isCFunction(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pop(int n)
|
|
|
|
void ScriptContext::pop(int n)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_pop(L, n);
|
|
|
|
lua_pop(L, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::popBoolean()
|
|
|
|
bool ScriptContext::popBoolean()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool b = (lua_toboolean(L, -1) != 0);
|
|
|
|
bool b = (lua_toboolean(L, -1) != 0);
|
|
|
|
pop();
|
|
|
|
pop();
|
|
|
|
return b;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::popInteger()
|
|
|
|
int ScriptContext::popInteger()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
double d = lua_tonumber(L, -1);
|
|
|
|
double d = lua_tonumber(L, -1);
|
|
|
|
pop();
|
|
|
|
pop();
|
|
|
|
return (int)d;
|
|
|
|
return (int)d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LuaScript::popString()
|
|
|
|
std::string ScriptContext::popString()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
std::string str;
|
|
|
|
if(lua_isstring(L, -1))
|
|
|
|
if(lua_isstring(L, -1))
|
|
|
@ -324,64 +300,64 @@ std::string LuaScript::popString()
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ScriptablePtr LuaScript::popClassInstance()
|
|
|
|
ScriptObjectPtr ScriptContext::popClassInstance()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ScriptablePtr object;
|
|
|
|
ScriptObjectPtr object;
|
|
|
|
if(isUserdata()) { // instances are store as userdata
|
|
|
|
if(isUserdata()) { // instances are store as userdata
|
|
|
|
object = *((ScriptablePtr *)lua_touserdata(L, -1));
|
|
|
|
object = *((ScriptObjectPtr *)lua_touserdata(L, -1));
|
|
|
|
if(!object)
|
|
|
|
if(!object)
|
|
|
|
reportErrorWithTraceback("attempt to retrive class instance from a object that is already expired");
|
|
|
|
reportErrorWithTraceback("attempt to retrive class instance from a object that is already expired");
|
|
|
|
} else if(!isNil()) // we accept nil values
|
|
|
|
} else if(!isNil()) // we accept nil values
|
|
|
|
reportErrorWithTraceback("couldn't retrive class instance, the value is not a scriptable type");
|
|
|
|
reportErrorWithTraceback("couldn't retrive class instance, the value is not a scriptobject type");
|
|
|
|
pop();
|
|
|
|
pop();
|
|
|
|
return object;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::popRef()
|
|
|
|
int ScriptContext::popRef()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pushNil()
|
|
|
|
void ScriptContext::pushNil()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_pushnil(L);
|
|
|
|
lua_pushnil(L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pushBoolean(bool b)
|
|
|
|
void ScriptContext::pushBoolean(bool b)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_pushboolean(L, b);
|
|
|
|
lua_pushboolean(L, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pushInteger(int32_t i)
|
|
|
|
void ScriptContext::pushInteger(int32_t i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_pushnumber(L, i);
|
|
|
|
lua_pushnumber(L, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pushString(const std::string& str)
|
|
|
|
void ScriptContext::pushString(const std::string& str)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_pushstring(L, str.c_str());
|
|
|
|
lua_pushstring(L, str.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pushClassInstance(const ScriptablePtr& object)
|
|
|
|
void ScriptContext::pushClassInstance(const ScriptObjectPtr& object)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(object) {
|
|
|
|
if(object) {
|
|
|
|
new(newUserdata(sizeof(ScriptablePtr))) ScriptablePtr(object);
|
|
|
|
new(newUserdata(sizeof(ScriptObjectPtr))) ScriptObjectPtr(object);
|
|
|
|
setMetatable(std::string(object->getScriptableName()) + "_mt");
|
|
|
|
setMetatable(std::string(object->getScriptObjectType()) + "_mt");
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
pushNil();
|
|
|
|
pushNil();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pushValue(int index)
|
|
|
|
void ScriptContext::pushValue(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_pushvalue(L, index);
|
|
|
|
lua_pushvalue(L, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::pushRef(int ref)
|
|
|
|
void ScriptContext::pushRef(int ref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LuaScript::getFunctionSourcePath(bool functionIsOnStack, int level)
|
|
|
|
std::string ScriptContext::getFunctionSourcePath(bool functionIsOnStack, int level)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
|
|
|
@ -415,14 +391,14 @@ std::string LuaScript::getFunctionSourcePath(bool functionIsOnStack, int level)
|
|
|
|
return path;
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LuaScript::callFunction(int numArgs, int numRets)
|
|
|
|
bool ScriptContext::callFunction(int numArgs, int numRets)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushValue(-numArgs - 1);
|
|
|
|
pushValue(-numArgs - 1);
|
|
|
|
g_resources.pushCurrentPath(getFunctionSourcePath(true));
|
|
|
|
g_resources.pushCurrentPath(getFunctionSourcePath(true));
|
|
|
|
|
|
|
|
|
|
|
|
int size = getStackSize();
|
|
|
|
int size = getStackSize();
|
|
|
|
int errorIndex = -numArgs - 2;
|
|
|
|
int errorIndex = -numArgs - 2;
|
|
|
|
lua_pushcfunction(L, &LuaScript::luaErrorHandler);
|
|
|
|
lua_pushcfunction(L, &ScriptContext::luaErrorHandler);
|
|
|
|
insert(errorIndex);
|
|
|
|
insert(errorIndex);
|
|
|
|
|
|
|
|
|
|
|
|
int ret = lua_pcall(L, numArgs, numRets, errorIndex);
|
|
|
|
int ret = lua_pcall(L, numArgs, numRets, errorIndex);
|
|
|
@ -443,13 +419,13 @@ bool LuaScript::callFunction(int numArgs, int numRets)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::callModuleField(const std::string& module, const std::string& field)
|
|
|
|
void ScriptContext::callModuleField(const std::string& module, const std::string& field)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
g_lua.rawGetGlobalTableField(module, field);
|
|
|
|
g_lua.rawGetGlobalTableField(module, field);
|
|
|
|
g_lua.callFunction();
|
|
|
|
g_lua.callFunction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::setupPackageLoader()
|
|
|
|
void ScriptContext::setupPackageLoader()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, "package"); // package
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, "package"); // package
|
|
|
|
lua_getfield(L, -1, "loaders"); // package.loaders, package
|
|
|
|
lua_getfield(L, -1, "loaders"); // package.loaders, package
|
|
|
@ -462,12 +438,12 @@ void LuaScript::setupPackageLoader()
|
|
|
|
numLoaders++;
|
|
|
|
numLoaders++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_pushinteger(L, numLoaders + 1); // at, package.loaders
|
|
|
|
lua_pushinteger(L, numLoaders + 1); // at, package.loaders
|
|
|
|
lua_pushcfunction(L, &LuaScript::luaPackageLoader); // luaPackageLoader, at, package.loaders
|
|
|
|
lua_pushcfunction(L, &ScriptContext::luaPackageLoader); // luaPackageLoader, at, package.loaders
|
|
|
|
lua_rawset(L, -3); // package.loaders
|
|
|
|
lua_rawset(L, -3); // package.loaders
|
|
|
|
lua_pop(L, 1); // (empty)
|
|
|
|
lua_pop(L, 1); // (empty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::registerClass(const std::string& klass, const std::string& baseClass)
|
|
|
|
void ScriptContext::registerClass(const std::string& klass, const std::string& baseClass)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// mt = {}
|
|
|
|
// mt = {}
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_newtable(L);
|
|
|
@ -475,19 +451,19 @@ void LuaScript::registerClass(const std::string& klass, const std::string& baseC
|
|
|
|
lua_setfield(L, LUA_REGISTRYINDEX, (klass + "_mt").c_str());
|
|
|
|
lua_setfield(L, LUA_REGISTRYINDEX, (klass + "_mt").c_str());
|
|
|
|
|
|
|
|
|
|
|
|
// set __index metamethod
|
|
|
|
// set __index metamethod
|
|
|
|
lua_pushcfunction(L, &LuaScript::luaIndexMetaMethod);
|
|
|
|
lua_pushcfunction(L, &ScriptContext::luaIndexMetaMethod);
|
|
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
|
|
|
|
|
|
|
|
// set __newindex metamethod
|
|
|
|
// set __newindex metamethod
|
|
|
|
lua_pushcfunction(L, &LuaScript::luaNewIndexMetaMethod);
|
|
|
|
lua_pushcfunction(L, &ScriptContext::luaNewIndexMetaMethod);
|
|
|
|
lua_setfield(L, -2, "__newindex");
|
|
|
|
lua_setfield(L, -2, "__newindex");
|
|
|
|
|
|
|
|
|
|
|
|
// set __eq metamethod
|
|
|
|
// set __eq metamethod
|
|
|
|
lua_pushcfunction(L, &LuaScript::luaEqualMetaMethod);
|
|
|
|
lua_pushcfunction(L, &ScriptContext::luaEqualMetaMethod);
|
|
|
|
lua_setfield(L, -2, "__eq");
|
|
|
|
lua_setfield(L, -2, "__eq");
|
|
|
|
|
|
|
|
|
|
|
|
// set __gc metamethod, which collects userdata
|
|
|
|
// set __gc metamethod, which collects userdata
|
|
|
|
lua_pushcfunction(L, &LuaScript::luaGarbageCollectMetaMethod);
|
|
|
|
lua_pushcfunction(L, &ScriptContext::luaGarbageCollectMetaMethod);
|
|
|
|
lua_setfield(L, -2, "__gc");
|
|
|
|
lua_setfield(L, -2, "__gc");
|
|
|
|
|
|
|
|
|
|
|
|
// klass = { }
|
|
|
|
// klass = { }
|
|
|
@ -536,7 +512,7 @@ void LuaScript::registerClass(const std::string& klass, const std::string& baseC
|
|
|
|
m_currentClass = klass;
|
|
|
|
m_currentClass = klass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFunction getFunction, LuaScript::LuaCFunction setFunction)
|
|
|
|
void ScriptContext::registerMemberField(const std::string& field, ScriptContext::LuaCFunction getFunction, ScriptContext::LuaCFunction setFunction)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(getFunction) {
|
|
|
|
if(getFunction) {
|
|
|
|
int functionId = m_functions.size();
|
|
|
|
int functionId = m_functions.size();
|
|
|
@ -547,7 +523,7 @@ void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFun
|
|
|
|
// push the function id
|
|
|
|
// push the function id
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
// store id in the closure
|
|
|
|
// store id in the closure
|
|
|
|
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
|
|
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
|
|
|
// store the function at the class field functionName
|
|
|
|
// store the function at the class field functionName
|
|
|
|
lua_setfield(L, -2, ("get_" + field).c_str());
|
|
|
|
lua_setfield(L, -2, ("get_" + field).c_str());
|
|
|
|
// pop the table
|
|
|
|
// pop the table
|
|
|
@ -563,7 +539,7 @@ void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFun
|
|
|
|
// push the function id
|
|
|
|
// push the function id
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
// store id in the closure
|
|
|
|
// store id in the closure
|
|
|
|
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
|
|
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
|
|
|
// store the function at the class field functionName
|
|
|
|
// store the function at the class field functionName
|
|
|
|
lua_setfield(L, -2, ("set_" + field).c_str());
|
|
|
|
lua_setfield(L, -2, ("set_" + field).c_str());
|
|
|
|
// pop the table
|
|
|
|
// pop the table
|
|
|
@ -571,7 +547,7 @@ void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFun
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::registerMemberFunction(const std::string& functionName, LuaCFunction function)
|
|
|
|
void ScriptContext::registerMemberFunction(const std::string& functionName, LuaCFunction function)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int functionId = m_functions.size();
|
|
|
|
int functionId = m_functions.size();
|
|
|
|
m_functions.push_back(function);
|
|
|
|
m_functions.push_back(function);
|
|
|
@ -581,14 +557,14 @@ void LuaScript::registerMemberFunction(const std::string& functionName, LuaCFunc
|
|
|
|
// push the function id
|
|
|
|
// push the function id
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
// store id in the closure
|
|
|
|
// store id in the closure
|
|
|
|
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
|
|
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
|
|
|
// store the function at the class field functionName
|
|
|
|
// store the function at the class field functionName
|
|
|
|
lua_setfield(L, -2, functionName.c_str());
|
|
|
|
lua_setfield(L, -2, functionName.c_str());
|
|
|
|
// pop the table
|
|
|
|
// pop the table
|
|
|
|
lua_pop(L, 1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::registerGlobalFunction(const std::string& functionName, LuaCFunction function)
|
|
|
|
void ScriptContext::registerGlobalFunction(const std::string& functionName, LuaCFunction function)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int functionId = m_functions.size();
|
|
|
|
int functionId = m_functions.size();
|
|
|
|
m_functions.push_back(function);
|
|
|
|
m_functions.push_back(function);
|
|
|
@ -596,12 +572,12 @@ void LuaScript::registerGlobalFunction(const std::string& functionName, LuaCFunc
|
|
|
|
// push the function id
|
|
|
|
// push the function id
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
lua_pushnumber(L, functionId);
|
|
|
|
// store id in the closure
|
|
|
|
// store id in the closure
|
|
|
|
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
|
|
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
|
|
|
// store the function in the global lua table
|
|
|
|
// store the function in the global lua table
|
|
|
|
lua_setfield(L, LUA_GLOBALSINDEX, functionName.c_str());
|
|
|
|
lua_setfield(L, LUA_GLOBALSINDEX, functionName.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScript::registerModule(const std::string& module)
|
|
|
|
void ScriptContext::registerModule(const std::string& module)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
registerClass(module);
|
|
|
|
registerClass(module);
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, module.c_str());
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, module.c_str());
|
|
|
@ -610,7 +586,7 @@ void LuaScript::registerModule(const std::string& module)
|
|
|
|
lua_pop(L, -1);
|
|
|
|
lua_pop(L, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::luaPackageLoader(lua_State* L)
|
|
|
|
int ScriptContext::luaPackageLoader(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string fileName = lua_tostring(L, -1);
|
|
|
|
std::string fileName = lua_tostring(L, -1);
|
|
|
|
fileName += ".lua";
|
|
|
|
fileName += ".lua";
|
|
|
@ -624,7 +600,7 @@ int LuaScript::luaPackageLoader(lua_State* L)
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::luaIndexMetaMethod(lua_State* L)
|
|
|
|
int ScriptContext::luaIndexMetaMethod(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// stack: key, obj
|
|
|
|
// stack: key, obj
|
|
|
|
std::string key = lua_tostring(L, -1); // key, obj
|
|
|
|
std::string key = lua_tostring(L, -1); // key, obj
|
|
|
@ -658,7 +634,7 @@ int LuaScript::luaIndexMetaMethod(lua_State* L)
|
|
|
|
g_lua.rawGet(key);
|
|
|
|
g_lua.rawGet(key);
|
|
|
|
g_lua.remove(-2);
|
|
|
|
g_lua.remove(-2);
|
|
|
|
} else if(g_lua.isUserdata()) {
|
|
|
|
} else if(g_lua.isUserdata()) {
|
|
|
|
g_lua.getScriptableField(g_lua.popClassInstance(), key);
|
|
|
|
g_lua.getScriptObjectField(g_lua.popClassInstance(), key);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
g_lua.pop();
|
|
|
|
g_lua.pop();
|
|
|
|
g_lua.pushNil();
|
|
|
|
g_lua.pushNil();
|
|
|
@ -668,7 +644,7 @@ int LuaScript::luaIndexMetaMethod(lua_State* L)
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::luaNewIndexMetaMethod(lua_State* L)
|
|
|
|
int ScriptContext::luaNewIndexMetaMethod(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// stack: value, key, obj
|
|
|
|
// stack: value, key, obj
|
|
|
|
lua_insert(L, -2); // key, value, obj
|
|
|
|
lua_insert(L, -2); // key, value, obj
|
|
|
@ -693,7 +669,7 @@ int LuaScript::luaNewIndexMetaMethod(lua_State* L)
|
|
|
|
g_lua.rawSet(key);
|
|
|
|
g_lua.rawSet(key);
|
|
|
|
g_lua.pop();
|
|
|
|
g_lua.pop();
|
|
|
|
} else if(g_lua.isUserdata()) {
|
|
|
|
} else if(g_lua.isUserdata()) {
|
|
|
|
g_lua.setScriptableField(g_lua.popClassInstance(), key);
|
|
|
|
g_lua.setScriptObjectField(g_lua.popClassInstance(), key);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
g_lua.pop(2);
|
|
|
|
g_lua.pop(2);
|
|
|
|
g_lua.reportErrorWithTraceback("unknown type in index metamethod");
|
|
|
|
g_lua.reportErrorWithTraceback("unknown type in index metamethod");
|
|
|
@ -702,14 +678,14 @@ int LuaScript::luaNewIndexMetaMethod(lua_State* L)
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::luaEqualMetaMethod(lua_State* L)
|
|
|
|
int ScriptContext::luaEqualMetaMethod(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!lua_isuserdata(L, -1) || !lua_isuserdata(L, -2)) {
|
|
|
|
if(!lua_isuserdata(L, -1) || !lua_isuserdata(L, -2)) {
|
|
|
|
lua_pop(L, 2);
|
|
|
|
lua_pop(L, 2);
|
|
|
|
lua_pushboolean(L, 0);
|
|
|
|
lua_pushboolean(L, 0);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ScriptablePtr *objectRef1 = (ScriptablePtr *)lua_touserdata(L, -1);
|
|
|
|
ScriptObjectPtr *objectRef1 = (ScriptObjectPtr *)lua_touserdata(L, -1);
|
|
|
|
ScriptablePtr *objectRef2 = (ScriptablePtr *)lua_touserdata(L, -2);
|
|
|
|
ScriptObjectPtr *objectRef2 = (ScriptObjectPtr *)lua_touserdata(L, -2);
|
|
|
|
lua_pop(L, 2);
|
|
|
|
lua_pop(L, 2);
|
|
|
|
if(objectRef1 == objectRef2)
|
|
|
|
if(objectRef1 == objectRef2)
|
|
|
|
lua_pushboolean(L, 1);
|
|
|
|
lua_pushboolean(L, 1);
|
|
|
@ -719,17 +695,17 @@ int LuaScript::luaEqualMetaMethod(lua_State* L)
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::luaGarbageCollectMetaMethod(lua_State* L)
|
|
|
|
int ScriptContext::luaGarbageCollectMetaMethod(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(lua_isuserdata(L, -1)) {
|
|
|
|
if(lua_isuserdata(L, -1)) {
|
|
|
|
ScriptablePtr *objectRef = (ScriptablePtr *)lua_touserdata(L, -1);
|
|
|
|
ScriptObjectPtr *objectRef = (ScriptObjectPtr *)lua_touserdata(L, -1);
|
|
|
|
objectRef->reset();
|
|
|
|
objectRef->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::luaFunctionCallback(lua_State* L)
|
|
|
|
int ScriptContext::luaFunctionCallback(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// look for function id
|
|
|
|
// look for function id
|
|
|
|
int id = lua_tonumber(L, lua_upvalueindex(1));
|
|
|
|
int id = lua_tonumber(L, lua_upvalueindex(1));
|
|
|
@ -743,7 +719,7 @@ int LuaScript::luaFunctionCallback(lua_State* L)
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LuaScript::luaErrorHandler(lua_State *L)
|
|
|
|
int ScriptContext::luaErrorHandler(lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// push debug
|
|
|
|
// push debug
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
|
|
|
|
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
|