summaryrefslogtreecommitdiff
path: root/src/honey_lua.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/honey_lua.c')
-rw-r--r--src/honey_lua.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/honey_lua.c b/src/honey_lua.c
new file mode 100644
index 0000000..076fb65
--- /dev/null
+++ b/src/honey_lua.c
@@ -0,0 +1,40 @@
+#include "common.h"
+
+void honey_lua_create_table(lua_State* L,
+ honey_lua_element* elements,
+ unsigned int n_elements)
+{
+ lua_createtable(L, 0, n_elements);
+
+ for (int i=0; i<n_elements; i++) {
+ honey_lua_push_element(L, elements[i]);
+ lua_setfield(L, -2, elements[i].name);
+ }
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+void honey_lua_push_element(lua_State* L, honey_lua_element element)
+{
+ switch(element.type) {
+ case HONEY_INT:
+ lua_pushinteger(L, element.data.integer);
+ break;
+
+ case HONEY_NUM:
+ lua_pushnumber(L, element.data.number);
+ break;
+
+ case HONEY_STRING:
+ lua_pushstring(L, element.data.string);
+ break;
+
+ case HONEY_FUNC:
+ lua_pushcfunction(L, element.data.function);
+ break;
+
+ default:
+ // this should never happen
+ break;
+ }
+}