Category:LSL List/ko

From Second Life Wiki
< Category:LSL List
Revision as of 18:14, 6 July 2011 by Dal Ghost (talk | contribs) (Created page with "{{LSL Header/ko|ml=*}}{{LSLC/ko|}}{{LSLC/ko|Types}} {{RightToc/ko}} 리스트는 여러 데이터형을 저장할 수 있는 특별한 데이터형 입니다. 리스트는 대…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

리스트는 여러 데이터형을 저장할 수 있는 특별한 데이터형 입니다.

리스트는 대괄호'[]'안에 쉼표','로 구분됩니다.

예제: <lsl>[0,1,2,3,4]

["예","아니요","아마도"]</lsl>

(주의: 다른 프로그래밍과 다르게 LSL에는 배열이 없습니다.)


다양한 데이터 유형

같은 리스트에서 문자열, 정수, 부동 소수점, 벡터 등을 저장할 수 있습니다.

예제: <lsl>//리스트안에 정수, 소수, 문자열, 벡터. [1,14.154,"재미잇나요?",<1,1,1>]</lsl>

하지만, 리스트안에는 리스트를 포함할수 없습니다.

<lsl>[1, "one", 2, "two"] + [3, "three"] // [1, "one", 2, "two", 3, "three"]와 같습니다.</lsl> 불가능 <lsl>[1, "one", 2, "two", [3, "three"]] // 불가능합니다.</lsl>

리스트에 요소를 추가하면 리스트가 데이터형을 자동으로 기억합니다.

해당 데이터형과 위치를 알아야 함수를 사용하여 데이터를 불러올수 있습니다. llList2<type>의 이름을 가진 함수들 : llList2String, llList2Vector, 등. (다음에 추가.)

리스트에서 특정위치의 데이터형을 llGetListEntryType함수를 통해 알수 있습니다.

팁! float를 리스트에 추가할때는 소수점으로 추가하셔야 합니다. (즉 1를 1.0로 넣어야 합니다.)

리스트를 문자열 데이터형을 바꿀 수 있습니다 <lsl>default {

    touch_start(integer total_number)
   {   
       list a = ["abc",1,2,3.14,<0,0,0>];
       llOwnerSay((string)a); // 출력:  abc123.140000<0.000000, 0.000000, 0.000000>
   }

}</lsl>

또는 do while를 사용해서 불러올수 있습니다. <lsl>default {

    touch_start(integer total_number)
   {   
       list a = ["abc","def","ghi","jkl","lmn","opq"];
       integer i;
       integer s = llGetListLength(a);
       do
       llOwnerSay(llList2String(a,i));
       while(s>++i);
   }

}</lsl>

일반적인 리스트 사용

리스트 카운트(직접 입력받을때마다 새는 방법) vs 리스트 길이

다음을 참고합시다. (어떤 사람들이 전쟁 - 지친 때까지 여행 경험도 마음을 수 있습니다):

<lsl>["네","아니요","아마도"]</lsl>

리스트의 길이는 3입니다. 목록의 길이는 llGetListLength() 함수에 의해 반환됩니다 :

<lsl>integer length = llGetListLength(mylist);</lsl>

하지만, 리스트는 0부터 시작하기때문에

위의 리스트에서 0은 "네" 1은 "아니요" 2은 "아마도" 입니다.

즉, 마지막 위치를 알기 위해 리스트의 길이인 3에서 -1해주면 찾을수 있습니다 :

<lsl>integer length = llGetListLength(mylist); string item = llList2String(myList,length - 1);</lsl>

리스트의 제한

(2/20/11 이러한 제한은 LSL와 Mono 모두 적용되지 않습니다.)

(적용되지 않는부분이라 번역기만을 이용함.)

스크립트가 실행되는 동안, 목록은 스크립트에서 사용할 메모리의 양을 제한하여, 필요에 따라 동적으로 커질 수 있습니다.

그러나, 컴파일 (일명 저장) 당시의 스크립트에서 하드코드된 미리 정의된 목록에 72 요소 제한이 있습니다. 누군가가 사용자에게 색상 선택의 과다를 제공하는 경우 이러한 긴, 미리 정의된 목록 예를 들어, 일반 있습니다.

팁! 당신이 정말로 미리 정의된 목록에서 72 개 이상의 이러한 선택이 필요한 경우, 2 (또는 이상) 컴파일러를 화나게하고, (state_entry 그들을 함께 가입하지리스트) 또는 적절한 어디를 :

<lsl>biggerlist = biglist01 + biglist02;</lsl>

리스트에 데이터값 추가

리스트 앞쪽에 데이터값을 추가는 여러방법이 있습니다 :

  1. myList = [new_item] + myList; Best method for Mono-LSL
  2. myList = myList + [new_item];
  3. myList += [new_item];
  4. myList = (myList=[]) + myList + [new_item];
  5. myList = myList + new_item;
  6. myList += new_item;
  7. myList = (myList=[]) + myList + new_item; Best method for LSO-LSL

=====메모=====(해석 미완)

  • Mono-LSL에서 다른 방법에 비해 효율적인 함수를 제공 2009년 8월 8일.
    • Note that prepending the new_item without brackets negates any memory savings in Mono-LSL.
    • Method 1 will consume more memory than other methods in LSO-LSL.
  • As of 8/8/2009 Method 7 returns the best value for savings in LSO-LSL.
    • Method 7 is better than Method 4 due to the fact that Method 7 takes up less script overhead.
    • Method 7 test script compiled to have a start memory of 15878, while Method 4 compiled to have a start memory of 15871. As a result Method 7 had more free memory than Method 4 at the end of the test operation.
  • Methods 2 & 3 compile to the same thing.
  • Methods 5 & 6 compile to the same thing.
  • Methods 5, 6 & 7 have a bytecode savings over methods 2, 3 & 4 respectively, though there is an LSO-LSL VM bug that causes the string & key typecasts to not stick properly: SVC-1710.
  • Methods 4 & 7 can result in a considerable memory savings in LSO-LSL over methods 2, 3, 5 & 6 (it helps reduce heap fragmentation, which would otherwise result in unusable blocks of heap memory)[1]. In Mono-LSL it provides no significant memory advantage or disadvantage.
    • Depending upon the situation (in LSO-LSL) this method may not provide any advantage what so ever. If in doubt profile the script with and without using this method.

리스트 연결

리스트는 +를 이용하여 간단하게 연결이 가능 :

<lsl>newlist = list01 + list02;

newlist = list01 + ["red","brown",<0,0,0>];</lsl>

참고 : 실제로 명령을 실행하면, 리스트 3개가 만들어 집니다. 이것은 메모리 사용량에 영향을 줄 수 있습니다.


리스트 지우기

리스트를 지우는것은 괄호만 넣으면 됩니다. :

<lsl>myList = [];</lsl>


함수에 리스트 넣기

함수에 리스트를 넣을경우 데이터형이 달라 잘못된 처리를 할수있습니다. 하지만, 유용하게 쓰일 수 있습니다. :

<lsl>myList = llListReplaceList(myList, ["myString"], 2, 2);</lsl>

2011,07,07 AM10:13 by.Dal Ghost(seoul city)

위의 코드에서는 llListReplaceList()를 사용하여 잘 작동하지만, 인해리스트의 전달 방법, 그리고 llListReplaceList(), llDeleteSubList(), llList2List()와 llListSortList() 등, 작업, 당신이 그 함수를 호출하여, 둘, 셋를 사용하여 종료하거나, 목록을 저장하는 데 필요한 메모리의 2,4 배 금액 수 있습니다! 이 문제를 방지하기 위해, 우리는 최적화의 작은 부분을 사용할 수 있습니다 당신이 이러한 함수에 전달하는 목록 (예를 들어 함수의 결과 목록을 덮어 쓰게됩니다 경우) 다시 읽어되지 않을 것을 알고있는 경우 다음 우리가 할 수있는 이 작업을 수행 :

<lsl>myList = llListReplaceList((myList = []) + myList, ["myString"], 2, 2);</lsl>

The effect of this is to greatly reduce the memory usage, in both LSO-LSL and Mono VMs, and also reduce the fragmentation of memory. This can also work for other cases other than function-calls, for example when concatenating lists (above), you may find that this nearly eliminates any memory problem:

<lsl>list list1 = ["a", "b", "c"]; list2 = ["d", "e", "f"]; list3 = (list1 = list2 = []) + list1 + list2;</lsl>

Processing a List Into Another List

A more complex case, but sometimes when processing a large list you may find that you are producing a similarly large list as a result. In such cases there is a very large risk of running out of memory. As a result, in any case where you know you will, or might, be working on a particularly large list, it will often be worth manipulating them similarly to:

<lsl>list myOutput = [];

integer i = 0; integer x = myList != []; for (; i < x; ++i) {

   if (i > 10) { // Prune list every 10 elements
       myList = llDeleteSubList((myList = []) + myList, 0, i - 1);
       x -= i;
       i = 0;
  }
  // Do some work here:
  myOutput += llList2List(myList, i, i); // A silly bit of example work

}</lsl>

This method (deleting every few list entries or strides) is preferable to deleting an entry every loop, as the cost of calling llDeleteSubList() is very high. It is up to the scripter to decide what their optimal chunk-size is for pruning an input list, as you will need to balance memory use with delete cost.

Strided lists

One common use of lists is to duplicate the functionality of structured collections of data (aka structs). Such collections, available in many programming languages, are absent from LSL.

In-world in SL, (still as of July 2008), a strided list is the closest you can get to storing limited amounts of data in some kind of structure that you can access and manipulate in a few, limited ways.

Strided lists allow you to store related data pieces grouped (aka "strided") in sets. You can determine how many pieces of data in each "grouping."

An example is best at this point. You might use a strided list to track the names, gender and rez dates of a group of avatars:

<lsl>list demographics = ["John Adams", "male", "2007-06-22", "Shirley Bassey", "female", "2005-11-02", "Matt Damon", "male", "2008-05-19"];</lsl>

This example has a stride of three, because each grouping (or stride) has three data elements. Index 0 ("John Adams") is the start of the first instance (because list counting starts a 0), index 3 ("Shirley Bassey") is the start of the second instance, and so on.

It is important that the pieces of information in each grouping are always entered in the same sequence for every instance of the grouping in the list! In the example above, this means that the name needs to be always the first of the three related elements. You should consider carefully the order in which you record information because the function to sort a list, llListSort, will only sort on the first element of the instances. In other words, if the avatar's rez date were the most important attribute for your script, then you would need to record it first, and the name second. If you wish to be able to sort by avatar last name rather than first name, the name should be added to the list in Lastname FirstName format (avoiding a comma, though, of course, unless you wanted LastName and FirstName treated as separate elements in the list.)

To add another person to the above list, you would do this:

<lsl>demographics += ["Dorthy Lamour", "female", "2010-01-22"];</lsl>


You cannot do any kind of fancy data analysis or manipulation with strided lists, as you can in off-world databases or spreadsheets, but they can meet some limited, in-world needs, if you don't have the resources to tie-in off-world tools. It should be noted that when manipulating extremely large strided lists, that if you expect to be editing the lists that you may wish to use one list for each "column", this may be more complex but significantly reduces the amount of memory required when manipulating the lists, though it will be a lot more difficult to sort.

Here are the tools we do have for strided lists:


The following three (as of July 2008) native LSL functions can be used with strided lists:


Here are some additional, user-created functions for working with strided lists:

function purpose
ListStridedMove Moves something in a strided list to another place in the strided list.
ListStridedRemove Removes part of a strided list.
ListStridedUpdate Updates part of a strided list.

Extended List Operations

These functions have been created and contributed by LSL users to perform operations not covered by built-in LSL functions.


function purpose
ListCast Processes a list so that its contents are of a single-type.
List_cast Processes a list so that its contents are converted from strings to their respective types.
ListCompare Compares two lists for equality
ListItemDelete Removes one element from a list.
ListKeyCase Changes the values of the whole list into uppercase or lowercase based on input
ListToWholeNumbers Given a list of floats, converts them all to whole numbers (aka integers.)
ListXorY Join two lists to make one new combined list, while also eliminating any resulting duplicates in the new list.
ListXandY This function examines two lists, and returns a new list composed of the elements that both lists have in common.
ListXnotY Show what x list has that y list is missing.
ListXxorY Returns a new list, composed of elements that were in either original script, but not both. Note: This is not the same as getting rid duplicates by preserving just one of each duplicated item. It goes further, and removes both items.
ListXequY Answers the question: is list X identical to list Y?
ListXneqY Answers the question: is list X different from list Y?
Replace Replaces a single occurrence of something in a list with something else that you specify.
Replace All Replaces all occurrences of 'from list' with those in 'to list' in 'src list'. Not as concise as the replace function above, but will handle multiple items at the same time.
ListUnique Given a list of elements, returns a list of only the unique individual elements in that list.
ccFixListDatatypes Walks a list, casts the elements to the appropriate types, and returns a fixed list. Useful for things like llSetPrimitiveParams when you've parsed your data out of a string.
2D Pseudo-Array A way to emulate the behavior of a 2 dimensional array.

Pages in category "LSL List/ko"

The following 8 pages are in this category, out of 8 total.