Procházet zdrojové kódy

Use const char* instead of std::string when using string parameters

std::string::c_str() would be used to convert them to const char*
anyway.
Ole před 9 roky
rodič
revize
928bb5fa15
3 změnil soubory, kde provedl 10 přidání a 10 odebrání
  1. 4 4
      lib/luwra/auxiliary.hpp
  2. 4 4
      lib/luwra/state.hpp
  3. 2 2
      lib/luwra/usertypes.hpp

+ 4 - 4
lib/luwra/auxiliary.hpp

@@ -48,9 +48,9 @@ void setMetatable(State* state, const char* name) {
  * \param value Global value
  */
 template <typename V> static inline
-void setGlobal(State* state, const std::string& name, V&& value) {
+void setGlobal(State* state, const char* name, V&& value) {
 	push(state, std::forward<V>(value));
-	lua_setglobal(state, name.c_str());
+	lua_setglobal(state, name);
 }
 
 /**
@@ -60,8 +60,8 @@ void setGlobal(State* state, const std::string& name, V&& value) {
  * \returns Value associated with the given name
  */
 template <typename V> static inline
-V getGlobal(State* state, const std::string& name) {
-	lua_getglobal(state, name.c_str());
+V getGlobal(State* state, const char* name) {
+	lua_getglobal(state, name);
 
 	V instance = read<V>(state, -1);
 	lua_pop(state, 1);

+ 4 - 4
lib/luwra/state.hpp

@@ -75,16 +75,16 @@ struct StateWrapper: Table {
 	 * Execute a piece of code.
 	 */
 	inline
-	int runString(const std::string& code) {
-		return luaL_dostring(state, code.c_str());
+	int runString(const char* code) {
+		return luaL_dostring(state, code);
 	}
 
 	/**
 	 * Execute a file.
 	 */
 	inline
-	int runFile(const std::string& filepath) {
-		return luaL_dofile(state, filepath.c_str());
+	int runFile(const char* filepath) {
+		return luaL_dofile(state, filepath);
 	}
 };
 

+ 2 - 2
lib/luwra/usertypes.hpp

@@ -238,7 +238,7 @@ namespace internal {
 		using T = StripUserType<U>;
 
 		static inline
-		void registerConstructor(State* state, const std::string& name) {
+		void registerConstructor(State* state, const char* name) {
 			setGlobal(state, name, &UserTypeWrapper<T>::template construct<A...>);
 		}
 	};
@@ -251,7 +251,7 @@ namespace internal {
 template <typename S> static inline
 void registerUserType(
 	State* state,
-	const std::string& ctor_name,
+	const char* ctor_name,
 	const FieldVector& methods = FieldVector(),
 	const FieldVector& meta_methods = FieldVector()
 ) {