File: dumper.lua

package info (click to toggle)
darktable 5.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 62,864 kB
  • sloc: ansic: 361,898; cpp: 102,446; xml: 19,813; lisp: 14,539; sh: 3,771; javascript: 3,264; perl: 1,925; python: 1,485; ruby: 975; makefile: 543; asm: 46; sql: 38; awk: 21
file content (136 lines) | stat: -rw-r--r-- 2,970 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136


para = function() return "\n" end
node_to_string = function(node,name) 
	if name then
		return name
	else
		return node:get_name()
	end
end

code = function(text) 
	return "<code>"..text.."</code>"
end
emphasis = function(text)
  return "<em>"..text.."</em>"
end

startlist = function() return "\n" end
endlist = function() return "\n" end
listel = function(text) return "\n* "..text end

url = function(text,content) 
  if content then
    return "<ulink url=\""..text.."\">"..content.."</ulink>"
  else
    return text
  end
end

require "content"
doc = require "core"
table = require "table"
dump = require("darktable.debug").dump
dt = require "darktable"


local function sorted_pairs (t, f)
	local a = {}
	for n in pairs(t) do table.insert(a, n) end
	table.sort(a, f)
	local i = 0      -- iterator variable
	local iter = function ()   -- iterator function
		i = i + 1
		if a[i] == nil then return nil
		else return a[i], t[a[i]]
		end
	end
	return iter
end

local print_node
local add_table_entry

local function print_content(obj,obj_name)
  local result 
  if(type(obj) == "boolean") then
    result = tostring(obj)
  elseif type(obj) == "string" then
    result = "[==["..obj.."]==]"
  elseif type(obj) == "table" and obj._luadoc_type then
    result = print_node(obj,obj_name)
  elseif type(obj) == "table" then
    result = "{\n"
    for k,v in sorted_pairs(obj) do
      result = result..add_table_entry(k,v,obj_name.."[\""..k.."\"]")
    end
    result = result.."}"
  elseif type(obj) == "number" then
    result = tostring(obj)
  elseif type(obj) == "nil" then
    result ="nil"
  else
    error("unhandle attribute type\n"..type(obj))
  end

  return result

end


local known = {}

function print_node(node,node_name)
  local result
  if known[node] then
    table.insert(known[node],node_name)
    return "{} --[=["..known[node].target.."]=]"
    --return "{}"
  else
    known[node] = {target = node_name }
  end
  result = "{\n"
  result = result..add_table_entry("__text",doc.get_text(node),node_name..".__text")
  result = result..add_table_entry("__attributes",node._luadoc_attributes,node_name..".__attributes")

  for k,v in node:unskipped_children() do
    result = result..add_table_entry(k,v,node_name.."[\""..k.."\"]")
  end
  result=result.."}"
  return result
end


add_table_entry = function(key,object,name)
  return "[\""..key.."\"]".." = "..  print_content(object,name)..  ",\n"

end


M = {}

function M.get_doc()
  result = "API = "..  print_node(doc.toplevel,"API").."\n"
  for _,known_entry in pairs(known) do
    for _,target in ipairs(known_entry) do
      result = result..target.." = "..known_entry["target"].."\n"
    end
  end
  return result..[==[return API
--
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
]==]

end


--for k, v in darktable.gui.libs:unskipped_children() do
--  print(v._luadoc_attributes["position"].."aaa")
--end



return M;
--
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua