File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -225,11 +225,15 @@ namespace lua {
225
225
set<const char *>(key, value);
226
226
}
227
227
228
- void setString (lua::String key, const std::string& string ) const {
229
- stack::push_str (_luaState, string. c_str (), string. length () );
228
+ void setData (lua::String key, const char * value, size_t length ) const {
229
+ stack::push_str (_luaState, value, length);
230
230
lua_setglobal (_luaState, key);
231
231
}
232
232
233
+ void setString (lua::String key, const std::string& string) const {
234
+ setData (key, string.c_str (), string.length ());
235
+ }
236
+
233
237
void set (lua::String key, const std::string& value) const {
234
238
setString (key, value);
235
239
}
Original file line number Diff line number Diff line change @@ -331,6 +331,13 @@ namespace lua {
331
331
set<const char *>(key, value);
332
332
}
333
333
334
+ template <typename K>
335
+ void setData (K key, const char * value, size_t length) const {
336
+ stack::push (_stack->state , key);
337
+ stack::push_str (_stack->state , value, length);
338
+ lua_settable (_stack->state , _stack->top + _stack->pushed - _stack->grouped );
339
+ }
340
+
334
341
template <typename K>
335
342
void setString (K key, const std::string& string) const {
336
343
stack::push (_stack->state , key);
Original file line number Diff line number Diff line change @@ -252,6 +252,13 @@ int main(int argc, char** argv)
252
252
assert ((stringValue = state[" text" ].toString ()) == " hello" );
253
253
assert ((stringValue = state[" text" ].toString ()) != " bannana" );
254
254
255
+ char binaryData[3 ];
256
+ binaryData[0 ] = ' a' ;
257
+ binaryData[1 ] = ' b' ;
258
+ binaryData[2 ] = ' c' ;
259
+ state.setData (" binary" , binaryData, 3 );
260
+ assert (strcmp (state[" binary" ], " abc" ) == 0 );
261
+
255
262
state.checkMemLeaks ();
256
263
return 0 ;
257
264
}
You can’t perform that action at this time.
0 commit comments