Skip to content

Commit 4eaea44

Browse files
authored
Merge pull request #5 from defold/bugfixs
Documentation fixes and script_api
2 parents d6b9059 + 937f07a commit 4eaea44

File tree

5 files changed

+356
-66
lines changed

5 files changed

+356
-66
lines changed

docs/_data/api.yml

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
constants:
2-
- name: webview.CALLBACK_RESULT_URL_OK
3-
- name: webview.CALLBACK_RESULT_URL_ERROR
4-
- name: webview.CALLBACK_RESULT_URL_LOADING
5-
- name: webview.CALLBACK_RESULT_EVAL_OK
6-
- name: webview.CALLBACK_RESULT_EVAL_ERROR
7-
8-
functions:
9-
- name: webview.create
10-
short_desc: Creates a webview
11-
desc: "Creates a webview instance. It can show HTML pages as well as evaluate
1+
- name: webview
2+
type: table
3+
desc: Functions and constants for interacting with webview APIs
4+
members:
5+
6+
- name: create
7+
type: function
8+
desc: Creates a webview instance.
9+
It can show HTML pages as well as evaluate
1210
Javascript. The view remains hidden until the first call. There can exist a
1311
maximum of 4 webviews at the same time.
1412

1513
On iOS, the callback will never get a `webview.CALLBACK_RESULT_EVAL_ERROR`,
1614
due to the iOS SDK implementation."
17-
params:
15+
parameters:
1816
- type: function
19-
params:
17+
parameters:
2018
- name: self
2119
type: object
2220
desc: The calling script
@@ -32,12 +30,16 @@ functions:
3230
- name: type
3331
type: enum
3432
desc: The type of callback
35-
options:
36-
- webview.CALLBACK_RESULT_URL_OK
37-
- webview.CALLBACK_RESULT_URL_ERROR
38-
- webview.CALLBACK_RESULT_URL_LOADING
39-
- webview.CALLBACK_RESULT_EVAL_OK
40-
- webview.CALLBACK_RESULT_EVAL_ERROR
33+
34+
- `webview.CALLBACK_RESULT_URL_OK`
35+
36+
- `webview.CALLBACK_RESULT_URL_ERROR`
37+
38+
- `webview.CALLBACK_RESULT_URL_LOADING`
39+
40+
- `webview.CALLBACK_RESULT_EVAL_OK`
41+
42+
- `webview.CALLBACK_RESULT_EVAL_ERROR`
4143

4244
- name: data
4345
type: table
@@ -59,7 +61,7 @@ functions:
5961
desc: The id number of the webview
6062

6163
examples:
62-
- example: |-
64+
- desc: |-
6365
```lua
6466
local function webview_callback(self, webview_id, request_id, type, data)
6567
if type == webview.CALLBACK_RESULT_URL_OK then
@@ -84,18 +86,18 @@ functions:
8486
local webview_id = webview.create(webview_callback)
8587
```
8688
87-
- name: webview.destroy
88-
short_desc: Destroys a webview
89+
- name: destroy
90+
type: function
8991
desc: Destroys an instance of a webview.
90-
params:
92+
parameters:
9193
- name: webview_id
9294
type: number
9395
desc: The webview id (returned by the `webview.create()` call)
9496

9597
- name: webview.open
96-
short_desc: Open a page using an URL
97-
desc: Opens a web page in the webview, using an URL. Once the request is done, the callback (registered in `webview.create()`) is invoked.
98-
params:
98+
desc: Opens a web page in the webview, using an URL.
99+
Once the request is done, the callback (registered in `webview.create()`) is invoked.
100+
parameters:
99101
- name: webview_id
100102
type: number
101103
desc: The webview id
@@ -110,15 +112,16 @@ functions:
110112
type: boolean
111113
desc: If true, the webview will stay hidden (default=false)
112114
examples:
113-
- example: |-
115+
- desc: |-
114116
```lua
115117
local request_id = webview.open(webview_id, "http://www.defold.com", {hidden = true})
116118
```
117119
118-
- name: webview.open_raw
119-
short_desc: Open a page using HTML
120-
desc: Opens a web page in the webview, using HTML data. Once the request is done, the callback (registered in `webview.create()`) is invoked.
121-
params:
120+
- name: open_raw
121+
type: function
122+
desc: Opens a web page in the webview, using HTML data.
123+
Once the request is done, the callback (registered in `webview.create()`) is invoked.
124+
parameters:
122125
- name: webview_id
123126
type: number
124127
desc: The webview id
@@ -129,16 +132,17 @@ functions:
129132
type: table
130133
desc: "A table of options for the request. See `webview.open()`"
131134
examples:
132-
- example: |-
135+
- desc: |-
133136
```lua
134137
local html = sys.load_resource("/main/data/test.html")
135138
local request_id = webview.open_raw(webview_id, html, {hidden = true})
136139
```
137140
138-
- name: webview.eval
139-
short_desc: Evaluates javascript in a webview
140-
desc: Evaluates JavaScript within the context of the currently loaded page (if any). Once the request is done, the callback (registered in `webview.create()`) is invoked. The callback will get the result in the `data["result"]` field.
141-
params:
141+
- name: eval
142+
type: function
143+
desc: Evaluates JavaScript within the context of the currently loaded page (if any).
144+
Once the request is done, the callback (registered in `webview.create()`) is invoked. The callback will get the result in the `data["result"]` field.
145+
parameters:
142146
- name: webview_id
143147
type: number
144148
desc: The webview id
@@ -149,37 +153,37 @@ functions:
149153
type: number
150154
desc: The id number of the request
151155
examples:
152-
- example: |-
156+
- desc: |-
153157
```lua
154158
local request_id = webview.eval(webview_id, "GetMyFormData()")
155159
```
156160
157-
- name: webview.set_visible
158-
short_desc: Shows or hides a webview
161+
- name: set_visible
162+
type: function
159163
desc: Shows or hides a webview
160-
params:
164+
parameters:
161165
- name: webview_id
162166
type: number
163167
desc: The webview id
164168
- name: visible
165169
type: number
166170
desc: If `0`, hides the webview. If non zero, shows the view
167171

168-
- name: webview.is_visible
169-
short_desc: Gets the visibility state of the webview
172+
- name: is_visible
173+
type: function
170174
desc: Returns the visibility state of the webview.
171-
params:
175+
parameters:
172176
- name: webview_id
173177
type: number
174178
desc: The webview id
175179
return:
176180
type: number
177181
desc: Returns `0` if not visible, `1` if it is visible
178182

179-
- name: webview.set_position
180-
short_desc: Sets the position and size of the webview
183+
- name: set_position
184+
type: function
181185
desc: Sets the position and size of the webview
182-
params:
186+
parameters:
183187
- name: webview_id
184188
type: number
185189
desc: The webview id
@@ -195,3 +199,16 @@ functions:
195199
- name: height
196200
type: number
197201
desc: The height of the webview (-1 to match screen height)
202+
203+
#*****************************************************************************************************
204+
205+
- name: CALLBACK_RESULT_URL_OK
206+
type: number
207+
- name: CALLBACK_RESULT_URL_ERROR
208+
type: number
209+
- name: CALLBACK_RESULT_URL_LOADING
210+
type: number
211+
- name: CALLBACK_RESULT_EVAL_OK
212+
type: number
213+
- name: CALLBACK_RESULT_EVAL_ERROR
214+
type: number

docs/_includes/type-function.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<td>{{ param.desc | markdownify }}
1515

1616
{% if param.type == "table" %}
17-
{% include type-table.md fields=param.fields %}
17+
{% include type-table.md fields=param.members %}
1818
{% endif %}
1919
</td>
2020
</tr>

docs/_includes/type-table.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<ul>
22
{% for field in include.fields %}
3-
<li><strong>{{ field.name }}</strong> <code>{{ field.type }}</code> - {{ field.desc | markdownify }}</li>
3+
<li>
4+
<strong>{{ field.name }}</strong>
5+
{% if field.optional %}
6+
(optional)
7+
{% endif %}
8+
<code>{{ field.type }}</code> - {{ field.desc | markdownify }}
9+
</li>
410
{% endfor %}
511
</ul>

docs/index.md

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
11
---
22
layout: default
33
---
4-
## Constants
5-
{% for constant in site.data.api.constants %}
6-
### <code>{{ constant.name }}</code>
7-
{{ constant.desc }}
4+
## Modules
5+
{% for item in site.data.api %}
6+
### <code>{{ item.name }}</code>
7+
{{ item.desc }}
88
{% endfor %}
99

10+
## Enums
11+
<table>
12+
<tbody>
13+
{% for module in site.data.api %}
14+
{% for item in module.members %}
15+
{% if item.type contains 'number' %}
16+
<tr>
17+
<td><strong>{{ module.name }}.{{ item.name }}</strong></td>
18+
<td>{{ item.desc | markdownify | replace: "[icon:attention]","<br><br>⚠️"}}</td>
19+
</tr>
20+
21+
{% endif %}
22+
{% endfor %}
23+
{% endfor %}
24+
</tbody>
25+
</table>
26+
27+
<hr>
28+
1029
## Functions
1130
<table>
1231
<tbody>
13-
{% for function in site.data.api.functions %}
32+
{% for module in site.data.api %}
33+
{% for item in module.members %}
34+
{% if item.type contains 'function' %}
1435
<tr>
15-
<td><a href="#{{ function.name | url_encode }}"><code>{{ function.name }}</code></a></td>
16-
<td>{{ function.short_desc }}</td>
36+
<td><a href="#{{ item.name | url_encode }}"><strong>{{ module.name }}.{{ item.name }}()</strong></a></td>
37+
<td>{{ item.desc | truncate: 80 }}</td>
1738
</tr>
39+
{% endif %}
40+
{% endfor %}
1841
{% endfor %}
1942
</tbody>
2043
</table>
2144

22-
{% for function in site.data.api.functions %}
45+
{% for module in site.data.api %}
46+
{% for function in module.members %}
47+
{% if function.type contains 'function' %}
2348
<div class="function-wrap">
24-
<h3 class="function-header"><a href="#{{ function.name | url_encode }}" id="{{ function.name | url_encode }}"><code>{{ function.name }}({% for param in function.params %}{{param.name}}{% unless forloop.last %}, {% endunless %}{% endfor %})</code></a></h3>
25-
{{ function.desc | markdownify }}
49+
<h3 class="function-header"><a href="#{{ function.name | url_encode }}" id="{{ function.name | url_encode }}"><code>{{ module.name }}.{{ function.name }}({% for param in function.parameters %}{{param.name}}{% unless forloop.last %}, {% endunless %}{% endfor %})</code></a></h3>
50+
{% if function.parameters %}
2651
<table>
2752
<thead>
2853
<tr>
@@ -32,31 +57,59 @@ layout: default
3257
</tr>
3358
</thead>
3459
<tbody>
35-
{% for param in function.params %}
60+
{% for param in function.parameters %}
3661
<tr>
37-
<td style="text-align: right;"><strong>{{ param.name }}</strong></td>
62+
<td style="text-align: right;">
63+
<strong>{{ param.name }}</strong>
64+
{% if param.optional %}
65+
(optional)
66+
{% endif %}
67+
</td>
3868
<td><code>{{ param.type }}</code></td>
3969
<td>{{ param.desc | markdownify }}
4070
{% if param.type == "function" %}
41-
{% include type-function.md params=param.params %}
71+
{% include type-function.md params=param.parameters %}
4272
{% endif %}
4373
{% if param.type == "table" %}
44-
{% include type-table.md fields=param.fields %}
74+
{% include type-table.md fields=param.members %}
4575
{% endif %}
4676
</td>
4777
</tr>
4878
{% endfor %}
4979
</tbody>
5080
</table>
51-
{% if function.return %}
52-
<h4>Returns</h4>
53-
<code class="inline-code-block">{{ function.return.type }}</code> {{ function.return.desc | markdownify }}
5481
{% endif %}
82+
{% if function.returns %}
83+
<table>
84+
<thead>
85+
<tr>
86+
<th>Return value</th>
87+
<th>Type</th>
88+
<th>Description</th>
89+
</tr>
90+
</thead>
91+
<tbody>
92+
<h4>Returns</h4>
93+
{% for return in function.returns %}
94+
<tr>
95+
<td>{{ return.name }}</td>
96+
<td><code class="inline-code-block">{{ return.type }}</code></td>
97+
<td>{{ return.desc | markdownify }}</td>
98+
</tr>
99+
{% endfor %}
100+
</tbody>
101+
</table>
102+
{% endif %}
103+
{{ function.desc | markdownify | replace: "[icon:attention]","<br><br>⚠️" | replace: "[type:string]","<code class='inline-code-block'>string</code>" | replace: "[type:number]","<code class='inline-code-block'>number</code>" | replace: "[type:table]","<code class='inline-code-block'>table</code>" | markdownify}}
104+
55105
{% if function.examples %}
56106
<h4>Examples</h4>
57107
{% for example in function.examples %}
58-
{{ example.example | markdownify }}
108+
{{ example.desc | markdownify }}
59109
{% endfor %}
60110
{% endif %}
61111
</div>
112+
113+
{% endif %}
114+
{% endfor %}
62115
{% endfor %}

0 commit comments

Comments
 (0)