본문 바로가기

Lua4

[LUA] http authorization (GET/POST) lua에서 HTTP로 인증을 받는 방법입니다. local http = require("socket.http");local ltn12 = require("ltn12"); local respbody = {}; -- urllocal request_url = "http://...testurl/test.lua"; -- user id / passwordlocal userinfo = "user_name:password"; -- post datalocal postData = "REQUEST_BODY"; if postData == nil thenhttp.request{url = request_url,sink = ltn12.sink.table(respbody),headers = { authorization = "Basic.. 2014. 1. 8.
[LUA] HTTP 요청 결과 (Response body) 얻기 LUA 에서 다른 사이트에 Request를 보낸 후 Response의 내용을 변수에 저장하는 방법입니다. 빨간색 부분의 URL을 수정해서 사용하시면 됩니다. local http = require("socket.http");local ltn12 = require("ltn12"); local respbody = {}; http.request{url = "http://tvpot.cdn.videofarm.daum.net/crossdomain.xml",sink = ltn12.sink.table(respbody),} local respString = table.concat(respbody); print ("## Response:");print (respString); ## Response:>Exit code: 0 .. 2014. 1. 8.
[LUA] 외부 application의 출력 내용(printf등)을 얻어오기 io.popen 1. 테스트를 위한 간단한 응용 프로그램 소스. (Console application) > 윈도우에서 VC++로 작성했으나, 리눅스 프로그램도 적용 가능합니다.#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]){printf("hello lua!!\n");return 0;} >> 출력 결과hello lua!! 2. lua 코드 (빨간색 부분이 실행할 파일의 경로) local f = io.popen("D:\\test1.exe", "r") if f thenlocal data = f:read("*all")f:close(); print ("result >> " .. data);end >> 출력 결과result >> hello lua!! >Exit code: 0 ※.. 2014. 1. 8.
[LUA] 파일 내용 읽어오기 io.open local f = io.open("D:\\temp\\test.xml", "r") if f thenlocal data = f:read("*all")f:close(); print (data);end >>출력 결과 (test.xml 파일의 내용이 출력됩니다)>lua -e "io.stdout:setvbuf 'no'" "test4.lua" >Exit code: 0 개발자 트위터 : http://twitter.com/shkam777 ※ 퍼가실땐 출처를 밝혀주세요. (http://shkam.tistory.com/) 2014. 1. 8.