hwstub_tool: fix various bugs, improve lua library

Change-Id: I7552c04b7e2bc6722ed29864d195ecb04acd8d71