Changeset 1306 for trunk/core/luascript.c
- Timestamp:
- 08/29/11 05:50:24 (21 months ago)
- File:
-
- 1 edited
-
trunk/core/luascript.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/luascript.c
r1183 r1306 362 362 } 363 363 364 /* 365 val=get_prop(id) 366 get propcase value identified by id 367 the propcase is read as a short and sign extended to an int 368 */ 364 369 static int luaCB_get_prop( lua_State* L ) 365 370 { 366 371 lua_pushnumber( L, shooting_get_prop( luaL_checknumber( L, 1 ) ) ); 367 372 return 1; 373 } 374 375 /* 376 val=get_prop_str(prop_id,length) 377 get the value of a propertycase as a string 378 numeric values may be extracted using string.byte or or the binstr.lua module 379 returns the value as a string, or false if the underlying propcase call returned non-zero 380 */ 381 static int luaCB_get_prop_str( lua_State* L ) { 382 void *buf; 383 unsigned size; 384 unsigned prop_id = luaL_checknumber( L, 1 ); 385 size = luaL_checknumber( L, 2 ); 386 buf = malloc(size); 387 if(!buf) { 388 return luaL_error( L, "malloc failed in luaCB_get_prop" ); 389 } 390 if(get_property_case(prop_id,buf,size) == 0) { 391 lua_pushlstring( L, buf, size ); 392 } else { 393 lua_pushboolean( L, 0); 394 } 395 free(buf); 396 return 1; 368 397 } 369 398 … … 536 565 } 537 566 567 /* 568 set_prop(id,value) 569 the value is treated as a short 570 */ 538 571 static int luaCB_set_prop( lua_State* L ) 539 572 { 540 int to, to1; 541 to = luaL_checknumber( L, 1 ); 542 to1 = luaL_checknumber( L, 2 ); 543 shooting_set_prop(to, to1); 544 return 0; 573 shooting_set_prop(luaL_checknumber( L, 1 ), luaL_checknumber( L, 2 )); 574 return 0; 575 } 576 577 /* 578 status=set_prop_str(prop_id,value) 579 set propertycase value as a string. Length is taken from the string 580 numeric propcase values may be assembled by setting byte values using string.char or the binstr module 581 status: boolean - true if the underlying propcase call returns 0, otherwise false 582 */ 583 static int luaCB_set_prop_str( lua_State *L ) { 584 int prop_id; 585 unsigned len; 586 const char *str; 587 prop_id = luaL_checknumber( L, 1 ); 588 str = luaL_checklstring( L, 2, &len ); 589 if(str && len > 0) { 590 lua_pushboolean( L, (set_property_case(prop_id,(void *)str,len) == 0)); 591 } else { 592 return luaL_error( L, "invalid value"); 593 } 594 return 1; 545 595 } 546 596 … … 1701 1751 FUNC(get_near_limit) 1702 1752 FUNC(get_prop) 1753 FUNC(get_prop_str) 1703 1754 FUNC(get_raw_count) 1704 1755 FUNC(get_raw_nr) … … 1725 1776 FUNC(set_nd_filter) 1726 1777 FUNC(set_prop) 1778 FUNC(set_prop_str) 1727 1779 FUNC(set_raw_nr) 1728 1780 FUNC(set_raw)
Note: See TracChangeset
for help on using the changeset viewer.