From c25467ff5c58b523fdb50ca074588567ab72d799 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Mon, 18 May 2015 18:24:16 +0900 Subject: [PATCH] Evas filters: Implement very basic print function --- src/lib/evas/filters/evas_filter_parser.c | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/lib/evas/filters/evas_filter_parser.c b/src/lib/evas/filters/evas_filter_parser.c index 1f9f9d3a12..16f8071fa6 100644 --- a/src/lib/evas/filters/evas_filter_parser.c +++ b/src/lib/evas/filters/evas_filter_parser.c @@ -1820,6 +1820,50 @@ _lua_generic_function(lua_State *L, const char *name, return instr->return_count; } +static int +_lua_print(lua_State *L) +{ + Eina_Strbuf *s; + int nargs = lua_gettop(L); + int i; + + if (nargs < 1) + { + DBG("LUA: (nothing)"); + return 0; + } + + s = eina_strbuf_new(); + + for (i = 1; i <= nargs; i++) + { + if (lua_isstring(L, i)) + eina_strbuf_append(s, lua_tostring(L, i)); + else if (lua_isnumber(L, i)) + { + double d = lua_tonumber(L, i); + + if (fabs(d - floor(d)) < 0.000001) + eina_strbuf_append_printf(s, "%d", (int) d); + else + eina_strbuf_append_printf(s, "%f", d); + } + else + eina_strbuf_append(s, "<>"); + eina_strbuf_append_char(s, ' '); + } + + INF("LUA: %s", eina_strbuf_string_get(s)); + eina_strbuf_free(s); + + return 0; +} + +static const struct luaL_Reg printlib[] = { + { "print", _lua_print }, + { NULL, NULL } +}; + #define LUA_GENERIC_FUNCTION(name) \ static int \ _lua_##name(lua_State *L) \ @@ -1860,6 +1904,11 @@ _lua_state_create(Evas_Filter_Program *pgm) luaopen_string(L); luaopen_math(L); + // Implement print + lua_getglobal(L, "_G"); + luaL_register(L, NULL, printlib); + lua_pop(L, 1); + // Store program lua_pushlightuserdata(L, (void *) &this_is_not_a_cat); lua_pushlightuserdata(L, pgm);