Thorough review of lslbasefuncs and associated files, adding new stuff.

- Scratch TODO item: Change shouldbeXXX to asserts.
  - shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.

- New base functions:
  - compare (for == and !=)
  - less (for <, >, <=, >=)

- minus() renamed to neg() for consistency. Affects testfuncs too.

- add() now supports key+string and string+key.

- Allow integers in place of floats. That has caused the addition of three utility functions:
  - ff (force float)
  - v2f (force floats in all components of a vector)
  - q2f (force floats in all components of a quaternion)
  Used everywhere where necessary.

  Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
  This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.

- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).

- Some functions marked for moving in an incoming commit.

- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.

- Document llListFindList better.

- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.

- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.

- Change order of some F32(Quaternion(...)) to not force so much instancing.

- Bugfix: llVecNorm did not return a Vector.
This commit is contained in:
Sei Lisa 2014-07-26 20:54:01 +02:00
parent de4a8d4dac
commit 4bff3aaf94
3 changed files with 316 additions and 194 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
import re
import math
from lslcommon import *
from lslbasefuncs import llStringTrim, shouldbestring, shouldbelist, InternalTypecast
from lslbasefuncs import llStringTrim, isstring, islist, InternalTypecast
JSON_INVALID = u'\uFDD0'
JSON_OBJECT = u'\uFDD1'
@ -470,7 +470,7 @@ def InternalJson2Elem(json):
return json
def llJson2List(json):
shouldbestring(json)
assert isstring(json)
json = llStringTrim(json, 3) # STRING_TRIM
if json == u'':
@ -553,8 +553,8 @@ def llJson2List(json):
return [InternalJson2Elem(json)]
def llJsonGetValue(json, lst):
shouldbestring(json)
shouldbelist(lst)
assert isstring(json)
assert islist(lst)
return InternalJsonFindValue(json, lst, ReturnsToken=False)
'''def InternalJsonRecuriveSetValue(json, lst, val):
@ -587,9 +587,9 @@ def llJsonGetValue(json, lst):
def llJsonSetValue(json, lst, val):
shouldbestring(json)
shouldbelist(lst)
shouldbestring(val)
assert isstring(json)
assert islist(lst)
assert isstring(val)
if lst == []:
# [] replaces the entire string no matter if it was invalid
if val == JSON_DELETE:
@ -605,16 +605,16 @@ def llJsonSetValue(json, lst, val):
'''
def llJsonValueType(json, lst):
shouldbestring(json)
shouldbelist(lst)
assert isstring(json)
assert islist(lst)
ret = InternalJsonFindValue(json, lst, ReturnsToken=True)
if ret == JSON_INVALID:
return ret
return ret[2]
def llList2Json(kind, lst):
shouldbestring(kind)
shouldbelist(lst)
assert isstring(kind)
assert islist(lst)
if kind == JSON_OBJECT:
ret = u'{'