Skip to content

Commit fdd4f59

Browse files
Add initialized function
1 parent 2ddb602 commit fdd4f59

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

webview.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int lua_webview_allocate(lua_State *l) {
162162
static int lua_webview_init(lua_State *l) {
163163
LuaWebView *lwv = (LuaWebView *)lua_webview_asudata(l, 1);
164164
int initialized = 0;
165-
if (lwv->initState == NULL) {
165+
if (lwv != NULL && lwv->initState == NULL) {
166166
int r = webview_init(&lwv->webview);
167167
if (r == 0) {
168168
initialized = 1;
@@ -173,6 +173,12 @@ static int lua_webview_init(lua_State *l) {
173173
return 1;
174174
}
175175

176+
static int lua_webview_initialized(lua_State *l) {
177+
LuaWebView *lwv = (LuaWebView *)lua_webview_asudata(l, 1);
178+
lua_pushboolean(l, lwv != NULL && lwv->initState != NULL);
179+
return 1;
180+
}
181+
176182
static const char *const lua_webview_loop_modes[] = {
177183
"default", "once", "nowait", NULL
178184
};
@@ -340,6 +346,7 @@ LUALIB_API int luaopen_webview(lua_State *l) {
340346
{ "allocate", lua_webview_allocate },
341347
{ "clean", lua_webview_clean },
342348
{ "init", lua_webview_init },
349+
{ "initialized", lua_webview_initialized },
343350
{ "loop", lua_webview_loop },
344351
{ "eval", lua_webview_eval },
345352
{ "callback", lua_webview_callback },

0 commit comments

Comments
 (0)