api spec 정리를 표로 만들었었다.
이걸 header file 형식으로 바꾸기 위해
1,returntype,function,parametertype,parameter,comments,win32api
,,,parametertype,parameter
이런 식으로 된 csv 파일을 만들었다.
for w in string.gmatch(Line, "(.-),") do
if (j == 3) then table.insert(Output.parameterTypes, w) end;
if (j == 4) then table.insert(Output.parameters, w) end;
j = j + 1;
end
에서 string.gmatch를 썼는데, string.find로 여러 변수 한번에 대입하기
를 쓸 껄 그랬다.
진작 20.3 - Captures 부터 봤어야 했다.
지금은 아무 것도 없는 빈 줄 찾기가 안된다. 빈 줄은 없어야돼.
parametertype에 해당하는 4번째 field는 언제나 비어있지 않아야해.
void 일 경우에 띄어쓰기 안하는 처리를 안했다.
마지막 파라미터에 쉼표가 안들어가야되는데, 실수했다.
Executables/lua*/work/apicsv2header.lua
dofile(파일이름)으로 실행하면 된다.
function PrintResult(Output)
local result = '';
if (Output.returnType and Output.funcName) then
if (Output.description) then
result = result .. '/** ' .. Output.description
.. '\n matches ' .. Output.win32 .. ' in win32'
.. ' */\n';
end
result = result ..
Output.returnType .. '\n' ..
Output.funcName .. '\n' .. '(' .. '\n';
end
if
table.getn(Output.parameterTypes) > 0
and table.getn(Output.parameters) > 0
then
for k1, v1 in ipairs(Output.parameters) do
result = result
.. Output.parameterTypes[k1];
if (Output.parameters[k1] ~= '') then
result = result .. '\t' .. Output.parameters[k1]
.. ',';
end
result = result .. '\n'
end
end
if (result ~= '') then result = result .. ');\n'; end
print(result);
end
local file = io.open("work/api.csv");
local I = 0;
local Output = {};
Output.parameterTypes = {};
Output.parameters = {};
repeat
local Line = file:read("*l");
if (Line == nil) then break; end;
Line = Line..",";
--
if (string.find(Line, "%d*,,,") == 1) then
local j = 0;
for w in string.gmatch(Line, "(.-),") do
if (j == 3) then table.insert(Output.parameterTypes, w) end;
if (j == 4) then table.insert(Output.parameters, w) end;
j = j + 1;
end
else --if (string.find(Line, ".*,.*,.*,.*")) then
-- if not string.find(Line, ".*,.*,.*,.*") then
-- break;
-- end
local j = 0;
if Output then
PrintResult(Output);
end
Output = {};
Output.parameterTypes = {};
Output.parameters = {};
for w in string.gmatch(Line, "(.-),") do
if (j == 1) then Output.returnType = w; end
if (j == 2) then Output.funcName = w; end
if (j == 3) then table.insert(Output.parameterTypes, w); end
if (j == 4) then table.insert(Output.parameters, w); end
if (j == 5) then Output.description = w; end
if (j == 6) then Output.win32 = w; end
j = j + 1;
end
end
I = I + 1;
until Line == nil;
PrintResult(Output);
file:close();
local file = io.open("work/api.csv");
local I = 0;
repeat
local Line = file:read("*l");
if (Line == nil) then break; end;
Line = Line..",";
local Output = {};
Output.parameterTypes = {};
Output.parameters = {};
--
if (string.find(Line, "%d*,,,") == 1) then
local j = 0;
for w in string.gmatch(Line, "(.-),") do
if (j == 3) then table.insert(Output.parameterTypes, w) end;
if (j == 4) then table.insert(Output.parameters, w) end;
j = j + 1;
end
else
local j = 0;
for w in string.gmatch(Line, "(.-),") do
if (j == 1) then Output.returnType = w; end
if (j == 2) then Output.funcName = w; end
if (j == 3) then table.insert(Output.parameterTypes, w); end
if (j == 4) then table.insert(Output.parameters, w); end
if (j == 5) then Output.description = w; end
if (j == 6) then Output.win32 = w; end
j = j + 1;
end
end
local result = '';
if (Output.returnType and Output.funcName) then
if I ~= 0 then
result = result .. ')' .. '\n';
end
if (Output.description) then
result = result .. '/** ' .. Output.description
.. '\n matches ' .. Output.win32 .. ' in win32'
.. ' */\n';
end
result = result ..
Output.returnType .. '\n' ..
Output.funcName .. '\n' .. '(' .. '\n';
end
if
table.getn(Output.parameterTypes) > 0
and table.getn(Output.parameters) > 0
then
for k1, v1 in ipairs(Output.parameters) do
result = result
.. Output.parameterTypes[k1];
if (Output.parameters[k1] ~= '') then
result = result .. '\t' .. Output.parameters[k1]
.. ',';
end
result = result .. '\n'
end
end
print(result);
I = I + 1;
until Line == nil;
if I ~= 0 then print(');\n'); end
file:close();