본문 바로가기

개발/LUA7

[LUA] 문자열 다루기 간단 예제 #2 루아에서 문자열 찾는 함수는 string.find 입니다. 얼마전에 문자열에서 '.' 을 찾을 일이 있어서 이 함수를 이용했는데 return 값이 좀 특이했습니다. local nStart, nEnd = string.find('123.23', '.') print(nStart, nEnd) -- result: 1 1 Lua 문서를 찾아 보니 Lua의 find 는 기본이 패턴이네요(패턴의 일부 기능만 지원) 그래서 '.' 을 찾을 때는 "%." 과 같이 lua 패턴 escape문자 %를 같이 처리하거나, Plain Text 검색임을 명시해야 합니다. local nStart, nEnd = string.find('123.23', '%.') print(nStart, nEnd) -- result: 4 4 local n.. 2020. 5. 24.
[LUA] TABLE 정렬(SORT) 루아 테이블 정렬 샘플입니다. 루아 문서에 있는 table.sort 를 우선 참고 table.sort (list [, comp]) Sorts list elements in a given order, in-place, from list[1] to list[#list]. If comp is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that not comp(list[i+1],list[i]) will be true after the sort). If comp is not gi.. 2019. 10. 19.
[LUA] 개발 환경 만들기 루아 설치하기 1. 루아 개발 사이트에서 루아 내려받기 http://www.lua.org/ The Programming Language Lua www.lua.org 2. 내려 받은 ZIP 파일을 열어 적당한 폴더 (예: d:/dev/lua) 에 풀어 준다. 단, lua53.exe 는 파일이름을 lua.exe 로 변경한다. 3. 시스템 속성창에서 환경 변수 Path에 Lua 실행파일의 위치를 추가한다. VSCODE 설치 1. Visual Studio Code 내려 받아 설치 https://code.visualstudio.com/ Visual Studio Code - Code Editing. Redefined Visual Studio Code is a code editor redefined and optim.. 2019. 9. 30.
[LUA] FOR 문 루아 FOR 문 기본 문법은 for var = start, end, (step) do ... end 식이다 파이썬이나 C/C++ 등과 다른 게 파이썬의 for 문은 end 조건 값과 같은 경우도 포함한다. 또한 테이블의 카운트를 구하는 편의 함수 #table 은 구성요소가 배열인 경우에만 제대로 계산된다 (아래 샘플 코드 참조) --> #table 은 table 내에 [1] 로 시작하는 배열의 개수를 구하기 때문에 해당 키가 없으면 사이즈를 구하지 못한다. print('--------------------------------------------------------------------') print('0 에서 99 까지 더하기 예제') print('----------------------------.. 2019. 9. 29.
[LUA] 함수 호출 CALL BY VALUE/CALL BY REFERENCE 루아 함수 호출 시 CALL BY VALUE/REF 테스트 코드입니다 print 의 결과는 --> 뒤에 있습니다 -- 목적: 루아 함수 call by value, call by reference 확인 -- call by value : nil, booleans, numbers , strings -- call by ref : table, function, thread, userdata -- print 의 결과는 --> 로 표시 function dumpTable(o) if type(o) == 'table' then local s = '{ ' for k,v in pairs(o) do -- key 가 숫자가 아닌 경우 "key" if type(k) ~= 'number' then k = '"'..k..'"' end.. 2019. 7. 28.
[LUA] 테이블 다루기 - 배열/맵/클래스 루아는 기본 TYPE 말고는 테이블이 거의 모든 역할을 하고 있어 제대로 이해 하는게 필요 합니다 루아 테이블에 대한 간단한 샘플 코드입니다 print 결과는 소스 코드에 --> 주석으로 추가되어 있습니다 -- 목적: 루아 테이블 공부하기 -- print 의 결과는 --> 로 표시 function dumpTable(o) if type(o) == 'table' then local s = '{ ' for k,v in pairs(o) do -- key 가 숫자가 아닌 경우 "key" if type(k) ~= 'number' then k = '"'..k..'"' end s = s .. '['..k..'] = ' .. dumpTable(v) .. ',' end return s .. '} ' else return .. 2019. 7. 28.
[LUA] 문자열 다루기 간단 예제 Lua를 사용한 간단한 문자열 예제 (기존 파이썬 문자열 예제 소스를 루아에 맞도록 수정) He 로 변경: *# He said: "Of course." and you said "Thank you" #* print('--------------------------------------------------------------------') print('소문자 만들기') print('--------------------------------------------------------------------') sText2 = string.lower( sText) print('소문자 만들기:', sText2) -- [Outpt] 소문자 만들기: *# they said: "of course." and you s.. 2019. 7. 27.