- Version
- 1.3.2
Contents
- Introduction
- Example
- Functions to implement
- Global functions
- Upload filter script
- Parsing HTML with gumbo-query
- Translating scripts into different languages
Introduction
Image Uploader is using scripts written in Squirrel 3 language. Squirrel is a high level imperative, object-oriented programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games.
Squirrel 3.0 reference manual
Squirrel 3.0 Standard Libraries manual
Scripts should be saved in utf-8 encoding in files with .nut
extension and placed in the Data/Scripts directory.
Example
test <- "example";
{
nm.setUrl("http://example.com/upload.php");
nm.addQueryParamFile("file", pathToFile, ExtractFileName(pathToFile),"");
nm.addQueryParam("submit", "Upload file!");
nm.doUploadMultipartData();
local response = nm.responseBody();
local directUrl = regex_simple(response, "\\[IMG\\](.+)\\[/IMG\\]",0);
options.setDirectUrl(directUrl);
return 1;
}
function regex_simple(data,regStr,start)
{
local ex = regexp(regStr);
local res = ex.capture(data, start);
local resultStr = "";
if(res != null){
resultStr = data.slice(res[1].begin, res[1].end);
}
return resultStr;
}
function GetFolderList(list)
{
return 1;
}
function CreateFolder(parentAlbum,album)
{
return 1;
}
function ModifyFolder(album)
{
return 1;
}
{
return ["Private", "Public"];
}
You have to implement at least one function — UploadFile
.
If you want to support album listing/creating/modifying, you have to implement also GetFolderList
, CreateFolder
, ModifyFolder
, GetFolderAccessTypeList
.
nm
- global object - is an instance of NetworkClient
ServerParams
- global object - is an instance of ServerSettingsStruct
Parsing HTML with gumbo-query
local txt = "<h1><a id=\"logo\">some link</a></h1>";
local doc = Document(txt);
print(doc.find(
"h1 a").text()+
"\r\n");
print(doc.find(
"h1 a").length()+
"\r\n");
print(doc.find(
"#logo").attr(
"class")+
"\r\n");
nm.doGet("http://zenden.ws");
doc = Document(nm.responseBody());
doc.find("a").each( function(index,elem) {
print(elem.text()+
"-\r\n");
});