Commit df003a63 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Initialize Lua in ProcessList and load plugins

parent d08cb255
......@@ -26,6 +26,12 @@ in the source distribution for its full text.
#include <hwloc.h>
#endif
#ifdef HAVE_LUA
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#endif
#ifndef MAX_NAME
#define MAX_NAME 128
#endif
......@@ -70,12 +76,20 @@ typedef struct ProcessList_ {
int cpuCount;
#ifdef HAVE_LUA
lua_State* L;
#endif
} ProcessList;
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* pl);
void ProcessList_goThroughEntries(ProcessList* pl);
#ifdef HAVE_LUA
void ProcessList_enableScripting(ProcessList* pl, lua_State* L);
#endif
}*/
ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
......@@ -112,12 +126,40 @@ void ProcessList_done(ProcessList* this) {
if (this->topologyOk) {
hwloc_topology_destroy(this->topology);
}
#endif
#ifdef HAVE_LUA
lua_close(this->L);
#endif
Hashtable_delete(this->processTable);
Vector_delete(this->processes);
Vector_delete(this->processes2);
}
#ifdef HAVE_LUA
void ProcessList_initScripting(ProcessList* this) {
lua_State* L = luaL_newstate();
luaL_openlibs(L);
this->L = L;
lua_newtable(L);
lua_pushvalue(L, 1);
lua_setglobal(L, "htop");
for (int i = 0; i < this->settings->nPlugins; i++) {
char* plugin = this->settings->plugins[i];
lua_getglobal(L, "require");
lua_pushliteral(L, "htop-plugins.");
lua_pushstring(L, plugin);
lua_concat(L, 2);
int ok = lua_pcall(L, 1, 1, 0);
if (ok == LUA_OK) {
lua_setfield(L, 1, plugin);
} else {
lua_pop(L, 1);
}
}
}
#endif
void ProcessList_setPanel(ProcessList* this, Panel* panel) {
this->panel = panel;
}
......
......@@ -20,6 +20,12 @@ in the source distribution for its full text.
#include <hwloc.h>
#endif
#ifdef HAVE_LUA
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#endif
#ifndef MAX_NAME
#define MAX_NAME 128
#endif
......@@ -64,17 +70,29 @@ typedef struct ProcessList_ {
int cpuCount;
#ifdef HAVE_LUA
lua_State* L;
#endif
} ProcessList;
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* pl);
void ProcessList_goThroughEntries(ProcessList* pl);
#ifdef HAVE_LUA
void ProcessList_enableScripting(ProcessList* pl, lua_State* L);
#endif
ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_done(ProcessList* this);
#ifdef HAVE_LUA
void ProcessList_initScripting(ProcessList* this);
#endif
void ProcessList_setPanel(ProcessList* this, Panel* panel);
void ProcessList_printHeader(ProcessList* this, RichString* header);
......
......@@ -26,8 +26,11 @@ in the source distribution for its full text.
#include <time.h>
#include <unistd.h>
#ifdef HAVE_LUA
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#endif
//#link m
......@@ -175,8 +178,6 @@ int main(int argc, char** argv) {
else
setlocale(LC_CTYPE, "");
lua_State* L = luaL_newstate();
CommandLineSettings flags = parseArguments(argc, argv); // may exit()
#ifdef HAVE_PROC
......@@ -194,6 +195,10 @@ int main(int argc, char** argv) {
Settings* settings = Settings_new(pl->cpuCount);
pl->settings = settings;
#ifdef HAVE_LUA
ProcessList_initScripting(pl);
#endif
Header* header = Header_new(pl, settings, 2);
Header_populateFromSettings(header);
......@@ -254,8 +259,6 @@ int main(int argc, char** argv) {
if(flags.pidWhiteList) {
Hashtable_delete(flags.pidWhiteList);
}
lua_close(L);
return 0;
}
......@@ -9,6 +9,9 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#ifdef HAVE_LUA
#endif
//#link m
// ----------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment