ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.16k stars 504 forks source link

Sol2 exposes typename from C++, namespace included on error #1378

Open DukeVengeance opened 2 years ago

DukeVengeance commented 2 years ago

On some errors, detailed_namespace::nested::Classname is exposed to user.

Execute Result: (Intended Error)

[string "-- local function AnotherFunction(table)..."]:109: attempt to perform arithmetic on a sol.detailed_namespace::nested::Classname* value (field 'classname_in_lua')

.lua:

function Initialize()
    class_name_in_lua = class_name_in_lua + 1
end

.cc:

// No effect on this //#define SOL_NO_EXCEPTIONS 1
#define SOL_ALL_SAFETIES_ON 1
#include "sol/sol.hpp"

/* Usertype: */
table.new_usertype<detailed_namespace::nested::Classname>("Classname",
    "Func", &detailed_namespace::nested::Classname::Func,
    /* ... */
    );

/* Error Handler Function: */
lua.safe_script(R"***(function ScriptError(msg) print("ScriptError: ".. msg) end)***");
sol::protected_function::set_default_handler(lua["ScriptError"]);

/* Executed as */
lua.safe_script(Read(".lua"), env, OnScriptError);
lua["Initialize"].call()

Can we somehow prevent leaking classnames with detailed namespaces to script users? Actually I don't think sol2 had performed some magic to get typename as string in C++?

Thanks for developing sol2!