浏览代码

Move `setlocale` from Lua to C++.

red-001 6 年之前
父节点
当前提交
bb28afcfc3
共有 3 个文件被更改,包括 5 次插入5 次删除
  1. 0 2
      builtin/init.lua
  2. 3 0
      src/script/cpp_api/s_base.cpp
  3. 2 3
      src/script/cpp_api/s_security.cpp

+ 0 - 2
builtin/init.lua

@@ -21,7 +21,6 @@ if core.print then
 	core.print = nil -- don't pollute our namespace
 end
 math.randomseed(os.time())
-os.setlocale("C", "numeric")
 minetest = core
 
 -- Load other files
@@ -47,7 +46,6 @@ elseif INIT == "mainmenu" then
 elseif INIT == "async" then
 	dofile(asyncpath .. "init.lua")
 elseif INIT == "client" then
-	os.setlocale = nil
 	dofile(clientpath .. "init.lua")
 else
 	error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))

+ 3 - 0
src/script/cpp_api/s_base.cpp

@@ -119,6 +119,9 @@ ScriptApiBase::ScriptApiBase() :
 
 	m_environment = NULL;
 	m_guiengine = NULL;
+
+	// Make sure Lua uses the right locale
+	setlocale(LC_NUMERIC, "C");
 }
 
 ScriptApiBase::~ScriptApiBase()

+ 2 - 3
src/script/cpp_api/s_security.cpp

@@ -249,9 +249,8 @@ void ScriptApiSecurity::initializeSecurityClient()
 	static const char *os_whitelist[] = {
 		"clock",
 		"date",
-		"difftime",	
-		"time",
-		"setlocale",
+		"difftime",
+		"time"
 	};
 	static const char *debug_whitelist[] = {
 		"getinfo",