@@ -6,6 +6,7 @@ use crate::sys::{
66use std:: ffi:: CString ;
77
88use rglua:: {
9+ cstr,
910 globals:: Lua :: { self , GLOBALSINDEX } ,
1011 lua_shared:: * ,
1112 rstr,
@@ -14,7 +15,7 @@ use rglua::{
1415
1516const NO_LUA_STATE : & str = "Didn't run lua code, lua state is not valid/loaded!" ;
1617const INVALID_LOG_LEVEL : * const i8 =
17- "Invalid log level (Should be 1-5, 1 being Error, 5 being Trace)\0 " . as_ptr ( ) as * const i8 ;
18+ cstr ! ( "Invalid log level (Should be 1-5, 1 being Error, 5 being Trace)" ) ;
1819
1920pub fn runLua ( realm : Realm , code : String ) -> Result < ( ) , & ' static str > {
2021 // Check if lua state is valid for instant feedback
@@ -69,21 +70,9 @@ extern "C" fn sautorun_require(state: LuaState) -> i32 {
6970
7071 let raw_path = luaL_checklstring ( state, 1 , 0 ) ;
7172
72- lua_getfield (
73- state,
74- rglua:: globals:: Lua :: GLOBALSINDEX ,
75- "sautorun\0 " . as_ptr ( ) as * const i8 ,
76- ) ;
77- lua_getfield (
78- state,
79- rglua:: globals:: Lua :: GLOBALSINDEX ,
80- "package\0 " . as_ptr ( ) as * const i8 ,
81- ) ;
82- lua_getfield (
83- state,
84- rglua:: globals:: Lua :: GLOBALSINDEX ,
85- "loaded\0 " . as_ptr ( ) as * const i8 ,
86- ) ;
73+ lua_getfield ( state, rglua:: globals:: Lua :: GLOBALSINDEX , cstr ! ( "sautorun" ) ) ;
74+ lua_getfield ( state, rglua:: globals:: Lua :: GLOBALSINDEX , cstr ! ( "package" ) ) ;
75+ lua_getfield ( state, rglua:: globals:: Lua :: GLOBALSINDEX , cstr ! ( "loaded" ) ) ;
8776 lua_getfield ( state, 2 , raw_path) ;
8877 if lua_toboolean ( state, -1 ) != 0 {
8978 return 1 ;
@@ -144,39 +133,39 @@ pub fn runLuaEnv(
144133 lua_createtable ( state, 0 , 0 ) ; // local t2 = {}
145134
146135 lua_pushstring ( state, identifier) ;
147- lua_setfield ( state, -2 , "NAME\0 " . as_ptr ( ) as * const i8 ) ; // t2.NAME = ...
136+ lua_setfield ( state, -2 , cstr ! ( "NAME" ) ) ; // t2.NAME = ...
148137
149138 lua_pushstring ( state, dumped_script) ;
150- lua_setfield ( state, -2 , "CODE\0 " . as_ptr ( ) as * const i8 ) ; // t2.CODE = ...
139+ lua_setfield ( state, -2 , cstr ! ( "CODE" ) ) ; // t2.CODE = ...
151140
152141 if let Ok ( ip) = CString :: new ( ip) {
153142 lua_pushstring ( state, ip. as_ptr ( ) ) ;
154143 } else {
155144 lua_pushnil ( state) ;
156145 }
157- lua_setfield ( state, -2 , "IP\0 " . as_ptr ( ) as * const i8 ) ;
146+ lua_setfield ( state, -2 , cstr ! ( "IP" ) ) ;
158147
159148 // If this is running before autorun, set SAUTORUN.STARTUP to true.
160149 lua_pushboolean ( state, startup as i32 ) ;
161- lua_setfield ( state, -2 , "STARTUP\0 " . as_ptr ( ) as * const i8 ) ;
150+ lua_setfield ( state, -2 , cstr ! ( "STARTUP" ) ) ;
162151
163152 lua_pushcfunction ( state, log) ;
164- lua_setfield ( state, -2 , "log\0 " . as_ptr ( ) as * const i8 ) ;
153+ lua_setfield ( state, -2 , cstr ! ( "log" ) ) ;
165154
166155 /*lua_createtable( state, 0, 0 ); // local t = {}
167156 lua_createtable( state, 0, 0 ); // local t2 = {}
168- lua_setfield( state, -2, "loaded\0".as_ptr() as *const i8 ); // package.loaded = t2
169- lua_setfield( state, -2, "package\0".as_ptr() as *const i8 ); // package = t
157+ lua_setfield( state, -2, cstr!( "loaded") ); // package.loaded = t2
158+ lua_setfield( state, -2, cstr!( "package") ); // package = t
170159 */
171160
172161 lua_pushcfunction ( state, sautorun_require) ;
173- lua_setfield ( state, -2 , "require\0 " . as_ptr ( ) as * const i8 ) ;
162+ lua_setfield ( state, -2 , cstr ! ( "require" ) ) ;
174163
175- lua_setfield ( state, -2 , "sautorun\0 " . as_ptr ( ) as * const i8 ) ;
164+ lua_setfield ( state, -2 , cstr ! ( "sautorun" ) ) ;
176165
177166 lua_createtable ( state, 0 , 0 ) ; // Create a metatable to make the env inherit from _G
178167 lua_pushvalue ( state, GLOBALSINDEX ) ;
179- lua_setfield ( state, -2 , "__index\0 " . as_ptr ( ) as * const i8 ) ;
168+ lua_setfield ( state, -2 , cstr ! ( "__index" ) ) ;
180169 lua_setmetatable ( state, -2 ) ;
181170
182171 lua_setfenv ( state, -2 ) ;
0 commit comments