static int export_list(int parent, int object, const char* name, const char*** list) { int i; int parArr = tbl_get(parent, name); int parLen = tbl_getlen_deep(parArr); int objArr = tbl_get(object, name); int objLen = tbl_getlen_deep(objArr); *list = (const char**)prj_newlist(parLen + objLen); for (i = 0; i < parLen; ++i) (*list)[i] = tbl_getstringi(parArr, i + 1); for (i = 0; i < objLen; ++i) (*list)[parLen + i] = tbl_getstringi(objArr, i + 1); return (parLen + objLen); }
char * core_getvar(char *varname) { if (!strcmp(varname, "?")) { /* Get last return of the shell */ char *lreturn = (char *)malloc(5); snprintf(lreturn, 4, "%d", glob_shell->lreturn); return lreturn; } if (tbl_containskey(glob_shell->lvar_tbl, varname)) return (char *)tbl_get(glob_shell->lvar_tbl, varname); return getenv(varname); }
static int export_pkgconfig(Package* package, int tbl) { int arr, obj; int len, i; arr = tbl_get(tbl, "config"); len = tbl_getlen(arr); package->configs = (PkgConfig**)prj_newlist(len); for (i = 0; i < len; ++i) { PkgConfig* config = ALLOCT(PkgConfig); package->configs[i] = config; config->prjConfig = project->configs[i]; obj = tbl_geti(arr, i + 1); config->objdir = tbl_getstring(obj, "objdir"); config->extension = export_value(tbl, obj, "targetextension"); config->prefix = export_value(tbl, obj, "targetprefix"); config->target = export_value(tbl, obj, "target"); /* Assign a default target, if none specified */ if (config->target == NULL) config->target = package->name; /* Pull out the value lists */ export_list(tbl, obj, "buildflags", &config->flags); export_list(tbl, obj, "buildoptions", &config->buildopts); export_list(tbl, obj, "defines", &config->defines); export_list(tbl, obj, "includepaths", &config->incpaths); export_list(tbl, obj, "libpaths", &config->libpaths); export_list(tbl, obj, "linkoptions", &config->linkopts); export_list(tbl, obj, "links", &config->links); /* Build the file list */ config->files = export_files(tbl, obj); /* Build a list of file configurations */ export_fileconfig(config, arr); } return 1; }
static int export_fileconfig(PkgConfig* config, int arr) { int obj, count, i; count = prj_getlistsize((void**)config->files); config->fileconfigs = (FileConfig**)prj_newlist(count); for (i = 0; i < count; ++i) { FileConfig* fconfig = ALLOCT(FileConfig); config->fileconfigs[i] = fconfig; obj = tbl_get(arr, config->files[i]); if (obj > 0) { fconfig->buildaction = tbl_getstring(obj, "buildaction"); } else { fconfig->buildaction = NULL; } } return 1; }
int script_export() { int tbl, arr, obj; int len, i; prj_open(); /* Copy out the list of available options */ tbl = tbl_get(LUA_REGISTRYINDEX, "options"); len = tbl_getlen(tbl); project->options = (Option**)prj_newlist(len); for (i = 0; i < len; ++i) { Option* option = ALLOCT(Option); project->options[i] = option; obj = tbl_geti(tbl, i + 1); option->flag = tbl_getstringi(obj, 1); option->desc = tbl_getstringi(obj, 2); } /* Copy out the project settings */ tbl = tbl_get(LUA_GLOBALSINDEX, "project"); project->name = tbl_getstring(tbl, "name"); project->path = tbl_getstring(tbl, "path"); project->script = tbl_getstring(tbl, "script"); /* Copy out the project configurations */ arr = tbl_get(tbl, "config"); len = tbl_getlen(arr); project->configs = (PrjConfig**)prj_newlist(len); for (i = 0; i < len; ++i) { PrjConfig* config = ALLOCT(PrjConfig); project->configs[i] = config; obj = tbl_geti(arr, i + 1); config->name = tbl_getstring(obj, "name"); config->bindir = export_value(tbl, obj, "bindir"); config->libdir = export_value(tbl, obj, "libdir"); } /* Copy out the packages */ tbl = tbl_get(LUA_REGISTRYINDEX, "packages"); len = tbl_getlen(tbl); project->packages = (Package**)prj_newlist(len); for (i = 0; i < len; ++i) { Package* package = ALLOCT(Package); package->index = i; project->packages[i] = package; obj = tbl_geti(tbl, i + 1); package->name = tbl_getstring(obj, "name"); package->path = tbl_getstring(obj, "path"); package->script = tbl_getstring(obj, "script"); package->lang = tbl_getstring(obj, "language"); package->kind = tbl_getstring(obj, "kind"); package->objdir = tbl_getstring(obj, "objdir"); package->url = tbl_getstring(obj, "url"); package->data = NULL; export_pkgconfig(package, obj); } return 1; }