diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index f6340a7..b9b5de4 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -181,7 +181,7 @@ namespace chaiscript // Both t and t.x share the same memory location, but do not represent // objects of the same type. if (itr != m_ptrs.end() - && itr->second.m_type_info.m_bare_type_info == data->m_type_info.m_bare_type_info) + && type_info_bare_equals(itr->second.m_type_info, data->m_type_info)) { (*data) = (itr->second); } diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 8e7d607..53439a3 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -416,7 +416,7 @@ namespace chaiscript itr != m_types.end(); ++itr) { - if (itr->second.m_bare_type_info == ti.m_bare_type_info) + if (type_info_bare_equals(itr->second, ti)) { return itr->first; } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 1324965..1d9a290 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -92,9 +92,9 @@ namespace chaiscript const Type_Info &ti = types[1]; if (!ti.m_bare_type_info || !(vals[0].get_type_info().m_bare_type_info) - || (*ti.m_bare_type_info) == (*user_type().m_bare_type_info) - || (*ti.m_bare_type_info) == (*user_type().m_bare_type_info) - || (*vals[0].get_type_info().m_bare_type_info) == (*ti.m_bare_type_info)) + || type_info_bare_equals(ti, user_type()) + || type_info_bare_equals(ti, user_type()) + || type_info_bare_equals(vals[0].get_type_info(), ti)) { return true; } else { diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 980dfcd..f77d8c0 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -65,7 +65,8 @@ namespace chaiscript bool operator==(const Type_Info &ti) const { - return ti.m_type_info == m_type_info; + return ti.m_type_info == m_type_info + || (ti.m_type_info && m_type_info && *ti.m_type_info == *m_type_info); } bool m_is_const; @@ -144,6 +145,20 @@ namespace chaiscript return detail::Get_Type_Info::get(); } + bool type_info_bare_equals(const Type_Info &l, const Type_Info &r) + { + if (l.m_bare_type_info == 0 + && r.m_bare_type_info == 0) + { + return true; + } else if (l.m_bare_type_info == 0 + || r.m_bare_type_info == 0) + { + return false; + } else { + return *(l.m_bare_type_info) == *(r.m_bare_type_info); + } + } } diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 12d23cb..46a8e92 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -9,7 +9,14 @@ #include #include + +#ifdef _POSIX_VERSION #include +#else +#ifdef _MSC_VER +#include +#endif +#endif #include "chaiscript_prelude.hpp" #include "chaiscript_parser.hpp" @@ -56,6 +63,10 @@ namespace chaiscript DLSym(DLModule &t_mod, const std::string &t_symbol) : m_symbol(reinterpret_cast(dlsym(t_mod.m_data, t_symbol.c_str()))) { + if (!m_symbol) + { + throw load_module_error(dlerror()); + } } T m_symbol; @@ -75,9 +86,109 @@ namespace chaiscript DLSym m_func; }; #else + +#ifdef _MSC_VER + + std::string GetErrorMessage(DWORD err) + { + LPSTR lpMsgBuf = 0; + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + lpMsgBuf, + 0, NULL ); + + std::string retval; +/* + int bsz = WideCharToMultiByte(codepage, + 0, + pw,-1, + 0,0, + 0,0); + if (bsz > 0) { + char p[bsz]; + int rc = WideCharToMultiByte(codepage, + 0, + pw,-1, + p,bsz, + 0,0); + if (rc != 0) { + p[bsz-1] = 0; + retval = p; + } + } + */ + + if (lpMsgBuf) + { + retval = lpMsgBuf; + } else { + retval = "Unknown error occured"; + } + + LocalFree(lpMsgBuf); + return retval; + } + struct Loadable_Module { + struct DLModule + { + DLModule(const std::string &t_filename) + : m_data(LoadLibrary(t_filename.c_str())) + { + if (!m_data) + { + throw load_module_error(GetErrorMessage(GetLastError())); + } + } + + ~DLModule() + { + FreeLibrary(m_data); + } + + HMODULE m_data; + }; + + template + struct DLSym + { + DLSym(DLModule &t_mod, const std::string &t_symbol) + : m_symbol(reinterpret_cast(GetProcAddress(t_mod.m_data, t_symbol.c_str()))) + { + if (!m_symbol) + { + throw load_module_error(GetErrorMessage(GetLastError())); + } + } + + T m_symbol; + }; + Loadable_Module(const std::string &t_module_name, const std::string &t_filename) + : m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name) + { + } + + ModulePtr get() + { + return m_func.m_symbol(); + } + + DLModule m_dlmodule; + DLSym m_func; + }; + +#else + struct Loadable_Module + { + Loadable_Module(const std::string &, const std::string &) { throw load_module_error("Loadable module support not available for your platform"); } @@ -87,7 +198,7 @@ namespace chaiscript throw load_module_error("Loadable module support not available for your platform"); } }; - +#endif #endif typedef boost::shared_ptr Loadable_Module_Ptr; diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 35ef711..109b138 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -210,7 +210,7 @@ namespace chaiscript try { ss.add_object(node->children[0]->text, Boxed_Value()); } - catch (reserved_word_error &rwe) { + catch (reserved_word_error &) { throw Eval_Error("Reserved word used as variable '" + node->children[0]->text + "'", node); } return ss.get_object(node->children[0]->text); @@ -708,7 +708,7 @@ namespace chaiscript param_names, _1), numparams, annotation, guard)), function_name); } - catch (reserved_word_error &rwe) { + catch (reserved_word_error &) { throw Eval_Error("Reserved word used as function name '" + function_name + "'", node); } return Boxed_Value(); diff --git a/msvc/chaiscript/chaiscript.sln b/msvc/chaiscript/chaiscript.sln index d8fced7..3df4595 100644 --- a/msvc/chaiscript/chaiscript.sln +++ b/msvc/chaiscript/chaiscript.sln @@ -5,6 +5,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chaiscript", "chaiscript.vc EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chai-example", "..\chai-example\chai-example.vcproj", "{CE422E94-B360-4588-8C65-6A9BE80798F9}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_module", "..\test_module\test_module.vcproj", "{775EDCC2-102F-4E75-A860-9AF398D04145}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -19,6 +21,10 @@ Global {CE422E94-B360-4588-8C65-6A9BE80798F9}.Debug|Win32.Build.0 = Debug|Win32 {CE422E94-B360-4588-8C65-6A9BE80798F9}.Release|Win32.ActiveCfg = Release|Win32 {CE422E94-B360-4588-8C65-6A9BE80798F9}.Release|Win32.Build.0 = Release|Win32 + {775EDCC2-102F-4E75-A860-9AF398D04145}.Debug|Win32.ActiveCfg = Debug|Win32 + {775EDCC2-102F-4E75-A860-9AF398D04145}.Debug|Win32.Build.0 = Debug|Win32 + {775EDCC2-102F-4E75-A860-9AF398D04145}.Release|Win32.ActiveCfg = Release|Win32 + {775EDCC2-102F-4E75-A860-9AF398D04145}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/msvc/chaiscript/chaiscript.vcproj b/msvc/chaiscript/chaiscript.vcproj index 4c185d7..4d65979 100644 --- a/msvc/chaiscript/chaiscript.vcproj +++ b/msvc/chaiscript/chaiscript.vcproj @@ -49,7 +49,7 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" - DisableLanguageExtensions="true" + DisableLanguageExtensions="false" TreatWChar_tAsBuiltInType="false" UsePrecompiledHeader="0" WarningLevel="4" diff --git a/msvc/test_module/test_module.vcproj b/msvc/test_module/test_module.vcproj new file mode 100644 index 0000000..881437b --- /dev/null +++ b/msvc/test_module/test_module.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test_module.cpp b/src/test_module.cpp index f561fd0..28e9160 100644 --- a/src/test_module.cpp +++ b/src/test_module.cpp @@ -7,9 +7,15 @@ std::string hello_world() return "Hello World"; } -extern "C" +#ifdef _MSC_VER +#define EXPORT __declspec(dllexport) +#else +#define EXPORT +#endif + +extern "C" { - chaiscript::ModulePtr create_chaiscript_module_test() +EXPORT chaiscript::ModulePtr create_chaiscript_module_test() { chaiscript::ModulePtr m(new chaiscript::Module());