@ -200,9 +200,9 @@ namespace MWLua
if constexpr ( std : : is_same_v < ObjectT , GObject > )
{ // Only for global scripts
objectT [ " addScript " ] = [ lua = context . mLua , luaManager = context . mLuaManager ] (
const GObject & object , std : : string_view path ) {
const LuaUtil : : ScriptsConfiguration & cfg = l ua- > getConfiguration ( ) ;
objectT [ " addScript " ] = [ context] ( const GObject & object , std : : string_view path ,
sol : : optional < sol : : table > initData ) {
const LuaUtil : : ScriptsConfiguration & cfg = context. mL ua- > getConfiguration ( ) ;
std : : optional < int > scriptId = cfg . findId ( path ) ;
if ( ! scriptId )
throw std : : runtime_error ( " Unknown script: " + std : : string ( path ) ) ;
@ -211,7 +211,12 @@ namespace MWLua
" Script without CUSTOM tag can not be added dynamically: " + std : : string ( path ) ) ;
if ( object . ptr ( ) . getType ( ) = = ESM : : REC_STAT )
throw std : : runtime_error ( " Attaching scripts to Static is not allowed: " + std : : string ( path ) ) ;
luaManager - > addCustomLocalScript ( object . ptr ( ) , * scriptId ) ;
if ( initData )
context . mLuaManager - > addCustomLocalScript (
object . ptr ( ) , * scriptId , LuaUtil : : serialize ( * initData , context . mSerializer ) ) ;
else
context . mLuaManager - > addCustomLocalScript (
object . ptr ( ) , * scriptId , cfg [ * scriptId ] . mInitializationData ) ;
} ;
objectT [ " hasScript " ] = [ lua = context . mLua ] ( const GObject & object , std : : string_view path ) {
const LuaUtil : : ScriptsConfiguration & cfg = lua - > getConfiguration ( ) ;