allow lua to clear the textbuffer
This commit is contained in:
parent
adba43320e
commit
50fc355a0f
6 changed files with 28 additions and 24 deletions
|
@ -1,25 +1,22 @@
|
|||
--[[ utility functions ]]--
|
||||
|
||||
function _el(name)
|
||||
return function(args)
|
||||
return { name, args }
|
||||
end
|
||||
end
|
||||
|
||||
t = _el("t")
|
||||
--
|
||||
|
||||
--[[ page module ]]--
|
||||
|
||||
page = {}
|
||||
|
||||
function page.Commit(content)
|
||||
--__ext_pageview_clear()
|
||||
function page.Set(text)
|
||||
__ext_pageview_set_content(text)
|
||||
end
|
||||
|
||||
function page.Append(content)
|
||||
for i, v in pairs(content) do
|
||||
-- tag_name = v[1]
|
||||
-- tag_props = v[2]
|
||||
|
||||
print(v[1], v[2])
|
||||
|
||||
__ext_pageview_append_tag(v[1], v[2])
|
||||
__ext_pageview_append_tag("t", v[1] or v)
|
||||
end
|
||||
end
|
||||
|
||||
function page.Commit(content)
|
||||
page.Set("")
|
||||
page.Append(content)
|
||||
end
|
6
lua.c
6
lua.c
|
@ -39,7 +39,13 @@ int lua_init_state(lua_State* L, struct application_state* state) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int pageview_set_content(lua_State* L) {
|
||||
const char* new_content = luaL_checkstring(L, 1);
|
||||
page_application_text_buffer_set_text(state, new_content);
|
||||
}
|
||||
|
||||
lua_create_c_function(L, "__ext_pageview_append_tag", pageview_append_tag);
|
||||
lua_create_c_function(L, "__ext_pageview_set_content", pageview_set_content);
|
||||
|
||||
status = lua_pcall_file(L, "corescripts/_global.lua");
|
||||
if (status != 0) return 1;
|
||||
|
|
3
main.c
3
main.c
|
@ -12,7 +12,8 @@ static void activate(GtkApplication* app, struct application_state* state) {
|
|||
page_application_init(state);
|
||||
int status = lua_init_state(state->L, state);
|
||||
if (status != 0) {
|
||||
printf("error: lua_init_state failed with non-zero error code %d\n", status);
|
||||
fprintf(stderr, "error: lua_init_state failed with non-zero error code %d\n", status);
|
||||
return;
|
||||
}
|
||||
page_application_show(state);
|
||||
lua_close(state->L);
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
function Home()
|
||||
return {
|
||||
t("Hello"),
|
||||
t(" wow")
|
||||
}
|
||||
end
|
||||
|
||||
page.Commit(Home())
|
||||
page.Commit{
|
||||
"yeah"
|
||||
}
|
4
ui.c
4
ui.c
|
@ -35,4 +35,8 @@ void page_application_text_buffer_append_text(struct application_state* state, c
|
|||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(state->pageview_buffer), &iter);
|
||||
gtk_text_buffer_insert(GTK_TEXT_BUFFER(state->pageview_buffer), &iter, display_text, -1);
|
||||
}
|
||||
|
||||
void page_application_text_buffer_set_text(struct application_state* state, const char* text) {
|
||||
gtk_text_buffer_set_text(state->pageview_buffer, text, -1);
|
||||
}
|
1
ui.h
1
ui.h
|
@ -18,5 +18,6 @@ struct application_state* page_application_new();
|
|||
void page_application_init(struct application_state* state);
|
||||
void page_application_show(struct application_state* state);
|
||||
void page_application_text_buffer_append_text(struct application_state* state, const char* display_text);
|
||||
void page_application_text_buffer_set_text(struct application_state* state, const char* text);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue