Merge branch 'master' into ChaiScript_5_0_CPP_11
Fix for issue #94 Conflicts: src/main.cpp
This commit is contained in:
		@@ -269,7 +269,8 @@ if(BUILD_TESTING)
 | 
				
			|||||||
  endif()
 | 
					  endif()
 | 
				
			||||||
endif(BUILD_TESTING)
 | 
					endif(BUILD_TESTING)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install(TARGETS chai ${MODULES} RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript )
 | 
					install(TARGETS chai chaiscript_stdlib ${MODULES} RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install(DIRECTORY include/chaiscript DESTINATION include
 | 
					install(DIRECTORY include/chaiscript DESTINATION include
 | 
				
			||||||
   PATTERN "*.hpp"
 | 
					   PATTERN "*.hpp"
 | 
				
			||||||
   PATTERN "*/.svn*" EXCLUDE
 | 
					   PATTERN "*/.svn*" EXCLUDE
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										82
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -23,6 +23,85 @@ char *mystrdup (const char *s) {
 | 
				
			|||||||
    return d;                            // Return the new string
 | 
					    return d;                            // Return the new string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void *cast_module_symbol(std::string (*t_path)())
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  union cast_union
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    std::string (*in_ptr)();
 | 
				
			||||||
 | 
					    void *out_ptr;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cast_union c;
 | 
				
			||||||
 | 
					  c.in_ptr = t_path;
 | 
				
			||||||
 | 
					  return c.out_ptr;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::string default_search_path()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#ifdef CHAISCRIPT_WINDOWS
 | 
				
			||||||
 | 
					  TCHAR path[2048];
 | 
				
			||||||
 | 
					  int size = GetModuleFileName(0, path, sizeof(path)-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  std::string exepath(path, size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  size_t secondtolastslash = exepath.rfind('\\', exepath.rfind('\\') - 1);
 | 
				
			||||||
 | 
					  if (secondtolastslash != std::string::npos)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    return exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\";
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    return "";
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  std::string exepath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  std::vector<char> buf(2048);
 | 
				
			||||||
 | 
					  ssize_t size = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ((size = readlink("/proc/self/exe", &buf.front(), buf.size())) != -1)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    exepath = std::string(&buf.front(), size);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (exepath.empty())
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if ((size = readlink("/proc/curproc/file", &buf.front(), buf.size())) != -1)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      exepath = std::string(&buf.front(), size);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (exepath.empty())
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if ((size = readlink("/proc/self/path/a.out", &buf.front(), buf.size())) != -1)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      exepath = std::string(&buf.front(), size);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (exepath.empty())
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    Dl_info rInfo; 
 | 
				
			||||||
 | 
					    memset( &rInfo, 0, sizeof(rInfo) ); 
 | 
				
			||||||
 | 
					    if ( !dladdr(cast_module_symbol(&default_search_path), &rInfo)  || !rInfo.dli_fname ) { 
 | 
				
			||||||
 | 
					      return "";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    exepath = std::string(rInfo.dli_fname);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  size_t secondtolastslash = exepath.rfind('/', exepath.rfind('/') - 1);
 | 
				
			||||||
 | 
					  if (secondtolastslash != std::string::npos)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    return exepath.substr(0, secondtolastslash) + "/lib/chaiscript/";
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    return "";
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char* readline(const char* p)
 | 
					char* readline(const char* p)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  std::string retval;
 | 
					  std::string retval;
 | 
				
			||||||
@@ -30,6 +109,7 @@ char* readline(const char* p)
 | 
				
			|||||||
  std::getline(std::cin, retval);
 | 
					  std::getline(std::cin, retval);
 | 
				
			||||||
  return std::cin.eof() ? NULL : mystrdup(retval.c_str());
 | 
					  return std::cin.eof() ? NULL : mystrdup(retval.c_str());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void add_history(const char*){}
 | 
					void add_history(const char*){}
 | 
				
			||||||
void using_history(){}
 | 
					void using_history(){}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -174,6 +254,8 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
    usepaths.push_back(usepath);
 | 
					    usepaths.push_back(usepath);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  std::string searchpath = default_search_path();
 | 
				
			||||||
 | 
					  modulepaths.push_back(searchpath);
 | 
				
			||||||
  modulepaths.push_back("");
 | 
					  modulepaths.push_back("");
 | 
				
			||||||
  if (modulepath)
 | 
					  if (modulepath)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user