File tree 1 file changed +21
-3
lines changed
1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -105,13 +105,31 @@ bool ModApiBasic::Initialize(lua_State* L,int top) {
105
105
return retval;
106
106
}
107
107
108
- // debug(text )
108
+ // debug(... )
109
109
// Writes a line to dstream
110
110
int ModApiBasic::l_debug (lua_State *L)
111
111
{
112
112
NO_MAP_LOCK_REQUIRED;
113
- std::string text = lua_tostring (L, 1 );
114
- dstream << text << std::endl;
113
+ // Handle multiple parameters to behave like standard lua print()
114
+ int n = lua_gettop (L);
115
+ lua_getglobal (L, " tostring" );
116
+ for (int i = 1 ; i <= n; i++){
117
+ /*
118
+ Call tostring(i-th argument).
119
+ This is what print() does, and it behaves a bit
120
+ differently from directly calling lua_tostring.
121
+ */
122
+ lua_pushvalue (L, -1 ); /* function to be called */
123
+ lua_pushvalue (L, i); /* value to print */
124
+ lua_call (L, 1 , 1 );
125
+ const char *s = lua_tostring (L, -1 );
126
+ if (i>1 )
127
+ dstream << " \t " ;
128
+ if (s)
129
+ dstream << s;
130
+ lua_pop (L, 1 );
131
+ }
132
+ dstream << std::endl;
115
133
return 0 ;
116
134
}
117
135
You can’t perform that action at this time.
0 commit comments