static void dotty(lua_State *L) { int status; const char *oldprogname = progname; progname = NULL; while ((status = loadline(L)) != -1) { if (status == 0) status = docall(L, 0, 0); report(L, status); if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ lua_getglobal(L, "print"); lua_insert(L, 1); if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) l_message(progname, lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1))); } } lua_settop(L, 0); /* clear stack */ fputs("\n", stdout); fflush(stdout); progname = oldprogname; }
static void dotty (lua_State *L) { int status; const char *oldprogname = progname; progname = NULL; while ((status = loadline(L)) != -1) { if (status == LUA_OK) status = docall(L, 0, 0); report(L, status); if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */ luaL_checkstack(L, LUA_MINSTACK, "too many results to print"); lua_getfield(L, LUA_ENVIRONINDEX, "print"); lua_insert(L, 1); if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK) l_message(progname, lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1))); } } lua_settop(L, 0); /* clear stack */ luai_writestring("\n", 1); fflush(stdout); progname = oldprogname; }
/* ==================================== */ scene * readscene(char *filename) /* ==================================== */ #undef F_NAME #define F_NAME "readscene" { FILE *fd = NULL; int32_t i, j, nobj, npoints, ret; scene *scn; char buf[1024]; fd = fopen(filename, "r"); if (!fd) { fprintf(stderr, "%s: cannot open file: %s\n", F_NAME, filename); return NULL; } ret = fscanf(fd, "%s", buf); if (strncmp(buf, "3Dscene", 7) != 0) { fprintf(stderr, "%s : bad file format 1 : %s\n", F_NAME, buf); return NULL; } ret = fscanf(fd, "%d", &nobj); if (ret != 1) { fprintf(stderr, "%s : bad file format 2\n", F_NAME); return NULL; } scn = (scene *)calloc(1,sizeof(scene)); if (scn == NULL) { fprintf(stderr, "%s : malloc failed\n", F_NAME); return NULL; } scn->nobj = nobj; scn->tabobj = (object **)calloc(1,nobj * sizeof(object *)); if (scn->tabobj == NULL) { fprintf(stderr, "%s: malloc failed\n", F_NAME); return NULL; } for (j = 0; j < nobj; j++) { ret = fscanf(fd, "%s", buf); if (ret != 1) { fprintf(stderr, "%s : bad file format 3\n", F_NAME); return NULL; } if (strncmp(buf, "line", 4) == 0) scn->tabobj[j] = loadline(fd); else if (strncmp(buf, "closedline", 10) == 0) scn->tabobj[j] = loadclosedline(fd); else if (strncmp(buf, "spline", 6) == 0) scn->tabobj[j] = loadspline(fd); else if (strncmp(buf, "closedspline", 12) == 0) scn->tabobj[j] = loadclosedspline(fd); else { fprintf(stderr, "%s : bad object type : %s\n", F_NAME, buf); return NULL; } } // for (j = 0; j < nobj; j++) fclose(fd); return scn; } // readscene()
static void nlua_thread(int pin, int pout, char *project, char *filename) { char cmd[4096]; int cmd_size; fprintf(stderr, "[err] Starting up Lua interpreter...\n"); fprintf(stdout, "[out] Starting up Lua interpreter...\n"); lua_State *L; L = lua_open(); if (!L) { cmd[0] = LC_ERROR; cmd_size = snprintf(cmd+1, sizeof(cmd)-2, "Unable to open lua") + 1; write(1, cmd, cmd_size); exit(0); } luaL_openlibs(L); lua_sethook(L, nlua_interpret_hook, LUA_MASKLINE, 0); /* If a filename was specified, load it in and run it */ if (project && *project) { char full_filename[2048]; if (filename && *filename) snprintf(full_filename, sizeof(full_filename)-1, "%s/%s/%s", PROJECT_DIR, project, filename); else snprintf(full_filename, sizeof(full_filename)-1, "%s/%s", PROJECT_DIR, project); if (luaL_dofile(L, full_filename)) { cmd[0] = LC_ERROR; cmd_size = snprintf(cmd+1, sizeof(cmd)-2, "Error: %s", lua_tostring(L, 1)) + 1; write(1, cmd, cmd_size); } } /* If no file was specified, enter REPL mode */ else { printf("Entering REPL mode...\n"); int status; while ((status = loadline(L)) != -1) { if (status == 0) status = docall(L, 0, 0); report(L, status); if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ lua_getglobal(L, "print"); lua_insert(L, 1); if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) l_message(progname, lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1))); } } lua_settop(L, 0); fputs("\n", stdout); fflush(stdout); } lua_close(L); close(pin); close(pout); exit(0); return; }
/* * Loads the mapping from a kbm file */ int Microtonal::loadkbm(const char *filename) { FILE *file=fopen(filename, "r"); int x; char tmp[500]; fseek(file,0,SEEK_SET); //loads the mapsize if (loadline(file,&tmp[0])!=0) return(2); if (sscanf(&tmp[0],"%d",&x)==0) return(2); if (x<1) x=0; if (x>127) x=127;//just in case... Pmapsize=x; //loads first MIDI note to retune if (loadline(file,&tmp[0])!=0) return(2); if (sscanf(&tmp[0],"%d",&x)==0) return(2); if (x<1) x=0; if (x>127) x=127;//just in case... Pfirstkey=x; //loads last MIDI note to retune if (loadline(file,&tmp[0])!=0) return(2); if (sscanf(&tmp[0],"%d",&x)==0) return(2); if (x<1) x=0; if (x>127) x=127;//just in case... Plastkey=x; //loads last the middle note where scale fro scale degree=0 if (loadline(file,&tmp[0])!=0) return(2); if (sscanf(&tmp[0],"%d",&x)==0) return(2); if (x<1) x=0; if (x>127) x=127;//just in case... Pmiddlenote=x; //loads the reference note if (loadline(file,&tmp[0])!=0) return(2); if (sscanf(&tmp[0],"%d",&x)==0) return(2); if (x<1) x=0; if (x>127) x=127;//just in case... PAnote=x; //loads the reference freq. if (loadline(file,&tmp[0])!=0) return(2); REALTYPE tmpPAfreq=440.0; if (sscanf(&tmp[0],"%f",&tmpPAfreq)==0) return(2); PAfreq=tmpPAfreq; //the scale degree(which is the octave) is not loaded, it is obtained by the tunnings with getoctavesize() method if (loadline(file,&tmp[0])!=0) return(2); //load the mappings if (Pmapsize!=0) { for (int nline=0;nline<Pmapsize;nline++) { if (loadline(file,&tmp[0])!=0) return(2); if (sscanf(&tmp[0],"%d",&x)==0) x=-1; Pmapping[nline]=x; }; Pmappingenabled=1; } else { Pmappingenabled=0; Pmapping[0]=0; Pmapsize=1; }; fclose(file); return(0); };