2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/doc/Hacking.md

52 lines
1.6 KiB
Markdown
Raw Normal View History

2016-02-18 05:05:07 +00:00
Hacking
=======
2017-04-08 10:44:59 +00:00
## How to Debug
We have a helper function called `logger.dbg` to help with debugging. You can use that function to print string and tables:
```lua
local logger = require("logger")
a = {"1", "2", "3"}
logger.dbg("table a: ", a)
```
Anything printed by `logger.dbg` starts with `DEBUG`.
On most target platforms, log output is saved to `crash.log` in the `koreader` directory.
2017-04-08 10:44:59 +00:00
```
04/06/17-21:44:53 DEBUG foo
```
In production code, remember that arguments are *always* evaluated in Lua, so,
don't inline complex computations in logger functions' arguments.
If you *really* have to, hide the whole thing behind a `dbg.is_on` branch,
like in [frontend/device/input.lua](https://github.com/koreader/koreader/blob/ba6fef4d7ba217ca558072f090849000e72ba142/frontend/device/input.lua#L1131-L1134).
## Bug hunting in KPV (KOReader's predecessor)
2017-04-08 10:44:59 +00:00
A real example of bug hunting in KPV's cache system: <https://github.com/koreader/kindlepdfviewer/pull/475>
2017-04-08 10:44:59 +00:00
2016-12-11 03:08:31 +00:00
## Developing UI widgets ##
2016-02-18 05:05:07 +00:00
`tools/wbuilder.lua` is your friend, if you need to create new UI widgets. It
2016-02-18 05:05:07 +00:00
sets up a minimal environment to bootstrap KOReader's UI framework to avoid
starting the whole reader. This gives you quick feedback loop while iterating
2016-02-29 00:53:47 +00:00
through your widget changes. It's also a handy tool for debugging widget
issues.
2016-02-18 05:05:07 +00:00
To get a taste of how it works, try running this command at the root of
KOReader's source tree:
```
./kodev wbuilder
```
It will spawn up an emulator window with a grid and simple timer widget for
demonstration.
You can add more `UIManager:show` call at the end of `tools/wbuilder.lua` to
2016-02-29 00:53:47 +00:00
test your new widgets.