Added autorun option to tpt.getscript()

This commit is contained in:
Bryan Hoyle 2011-08-25 11:14:27 -04:00
parent a2ce9d6db7
commit 951a396e60

View File

@ -1072,12 +1072,13 @@ return 0;
} }
int luatpt_getscript(lua_State* l) int luatpt_getscript(lua_State* l)
{ {
char *fileid = NULL, *filedata = NULL, *fileuri = NULL, *fileauthor = NULL, *filename = NULL, *lastError = NULL; char *fileid = NULL, *filedata = NULL, *fileuri = NULL, *fileauthor = NULL, *filename = NULL, *lastError = NULL, *luacommand = NULL;
int len, ret; int len, ret,run_script;
FILE * outputfile; FILE * outputfile;
fileauthor = mystrdup(luaL_optstring(l, 1, "")); fileauthor = mystrdup(luaL_optstring(l, 1, ""));
fileid = mystrdup(luaL_optstring(l, 2, "")); fileid = mystrdup(luaL_optstring(l, 2, ""));
run_script = luaL_optint(l, 3, 0);
if(!fileauthor || !fileid || strlen(fileauthor)<1 || strlen(fileid)<1) if(!fileauthor || !fileid || strlen(fileauthor)<1 || strlen(fileid)<1)
goto fin; goto fin;
if(!confirm_ui(vid_buf, "Do you want to install script?", fileid, "Install")) if(!confirm_ui(vid_buf, "Do you want to install script?", fileid, "Install"))
@ -1133,9 +1134,16 @@ int luatpt_getscript(lua_State* l)
goto fin; goto fin;
} }
fputs(filedata, outputfile); fputs(filedata, outputfile);
fclose(outputfile); fclose(outputfile);
outputfile = NULL; outputfile = NULL;
if(run_script)
{
luacommand = malloc(strlen(filename)+20);
sprintf(luacommand,"dofile(\"%s\")",filename);
luacon_eval(luacommand);
}
fin: fin:
if(fileid) free(fileid); if(fileid) free(fileid);
@ -1143,6 +1151,8 @@ fin:
if(fileuri) free(fileuri); if(fileuri) free(fileuri);
if(fileauthor) free(fileauthor); if(fileauthor) free(fileauthor);
if(filename) free(filename); if(filename) free(filename);
if(luacommand) free(luacommand);
luacommand = NULL;
if(lastError) return luaL_error(l, lastError); if(lastError) return luaL_error(l, lastError);
return 0; return 0;