- /* Register all the functions we implement in C */
- lua_newtable(script->lua_state);
- for (size_t i = 0; i < STATIC_ARRAY_SIZE(lua_c_functions); i++) {
- lua_pushcfunction(script->lua_state, lua_c_functions[i].func);
- lua_setfield(script->lua_state, -2, lua_c_functions[i].name);
- }
- lua_setglobal(script->lua_state, "collectd");
+/* Load the 'collectd' library */
+#if LUA_VERSION_NUM < 502
+ lua_pushcfunction(script->lua_state, open_collectd);
+ lua_pushstring(script->lua_state, "collectd");
+ lua_call(script->lua_state, 1, 0);
+#else
+ luaL_requiref(script->lua_state, "collectd", open_collectd, 1);
+ lua_pop(script->lua_state, 1);
+#endif