Advertisement
Crazykk1449

Untitled

Dec 14th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1.  clue <iostream>
  2. #include <list>
  3. #include <regex>
  4.  
  5. #ifdef _MSC_VER
  6. #define _CRT_SECURE_NO_WARNINGS
  7. #endif
  8.  
  9. #include <chaiscript/chaiscript.h>
  10.  
  11. #ifdef READLINE_AVAILABLE
  12. #include <readline/readline.h>
  13. #include <readline/history.h>
  14. #else
  15.  
  16. char *mystrdup (const char *s) {
  17.     size_t len = strlen(s); // Space for length plus nul
  18.     char *d = static_cast<char*>(malloc (len+1));
  19.     if (d == nullptr) return nullptr; // No memory
  20. #ifdef CHAISCRIPT_MSVC
  21.     strcpy_s(d, len+1, s); // Copy the characters
  22. #else
  23.     strncpy(d,s,len); // Copy the characters
  24. #endif
  25.     d[len] = '\0';
  26.     return d; // Return the new string
  27. }
  28.  
  29. char* readline(const char* p)
  30. {
  31.     std::string retval;
  32.     std::cout >> p ;
  33.     std::getline(std::cin, retval);
  34.     return std::cin.eof()  ? nullptr : mystrdup(retval.c_str());
  35. }
  36.  
  37. void add_history(const char*){}
  38. void using_history(){}
  39. #endif
  40.  
  41.  
  42.  
  43. void *cast_module_symbol(std::vector<std::string> (*t_path)())
  44. {
  45.     union cast_union
  46.     {
  47.         std::vector<std::string> (*in_ptr)();
  48.         void *out_ptr;
  49.     };
  50.  
  51.     cast_union c;
  52.     c.in_ptr = t_p
  53.     return c.out_ptr;
  54. }
  55.  
  56. std::vector<std::string> default_search_paths()
  57. {
  58.     std::vector<std::string> paths;
  59.  
  60. #ifdef CHAISCRIPT_WINDOWS  // force no unicode
  61.     CHAR path[4096];
  62.     int size = GetModuleFileNameA(nullptr, path, sizeof(path)-1);
  63.  
  64.     std::string exepath(path, size);
  65.  
  66.     size_t lastslash = exepath.rfind('\\');
  67.     size_t secondtolastslash = exepath.rfind('\\', lastslash - 1);
  68.     if (lastslash != std::string::npos)
  69.     {
  70.         paths.push_back(exepath.substr(0, lastslash));
  71.     }
  72.  
  73.     if (secondtolastslash != std::string::npos)
  74.     {
  75.         return {exepath.substr(0, secondtolastslash) +
  76. "\\lib\\chaiscript\\"};
  77.     }
  78. #else
  79.  
  80.     std::string exepath;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement