Move index_error_maker into new file (ScriptUtil.h). Add newindex_error_maker. Make them call ScriptAssert instead of just throwing an exception so it won't terminate the application on WARN or SILENT error modes.

This commit is contained in:
hispidence 2021-08-20 01:37:49 +01:00
parent 6727138e64
commit e74fa376d1
4 changed files with 17 additions and 7 deletions

View file

@ -3,13 +3,6 @@
#include <functional>
#include <string>
#define index_error_maker(CPP_TYPE, LUA_CLASS_NAME) [](CPP_TYPE & item, sol::object key) \
{ \
std::string err = "Attempted to read non-existant var \"" + key.as<std::string>() + "\" from " + LUA_CLASS_NAME; \
throw TENScriptException(err); \
}
template <typename S> using callbackSetName = std::function<bool(std::string const&, S identifier)>;
using callbackRemoveName = std::function<bool(std::string const&)>;

View file

@ -0,0 +1,13 @@
#pragma once
#define index_error_maker(CPP_TYPE, LUA_CLASS_NAME) [](CPP_TYPE & item, sol::object key) \
{ \
std::string err = "Attempted to read non-existant var \"" + key.as<std::string>() + "\" from " + LUA_CLASS_NAME; \
ScriptAssert(false, err);\
}
#define newindex_error_maker(CPP_TYPE, LUA_CLASS_NAME) [](CPP_TYPE & item, sol::object key) \
{ \
std::string err = "Attempted to set non-existant var \"" + key.as<std::string>() + "\" of " + LUA_CLASS_NAME; \
ScriptAssert(false, err);\
}

View file

@ -410,6 +410,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"</Command>
<ClInclude Include="Scripting\LuaHandler.h" />
<ClInclude Include="Scripting\ObjectIDs.h" />
<ClInclude Include="Scripting\ScriptAssert.h" />
<ClInclude Include="Scripting\ScriptUtil.h" />
<ClInclude Include="Specific\configuration.h" />
<ClInclude Include="Specific\IO\ChunkId.h" />
<ClInclude Include="Specific\IO\ChunkWriter.h" />

View file

@ -1050,6 +1050,9 @@
<ClInclude Include="Scripting\ItemEnumPair.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="Scripting\ScriptUtil.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Game\box.cpp">