mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Updated httpc.c to the latest ctrulib, fixed the cfgu example.
The name is still buggy, can't find why.
This commit is contained in:
parent
499bfa99a3
commit
a380f09a34
2 changed files with 53 additions and 9 deletions
|
|
@ -36,6 +36,7 @@ local models = {
|
||||||
[cfgu.MODEL_N3DSXL] = "New 3DS XL"
|
[cfgu.MODEL_N3DSXL] = "New 3DS XL"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfgu.init()
|
||||||
while ctr.run() do
|
while ctr.run() do
|
||||||
hid.read()
|
hid.read()
|
||||||
keys = hid.keys()
|
keys = hid.keys()
|
||||||
|
|
@ -45,7 +46,7 @@ while ctr.run() do
|
||||||
gfx.text(2, 2, "CFGU example")
|
gfx.text(2, 2, "CFGU example")
|
||||||
gfx.text(2, 20, "Region: "..regions[cfgu.getRegion()])
|
gfx.text(2, 20, "Region: "..regions[cfgu.getRegion()])
|
||||||
gfx.text(2, 30, "Model: "..models[cfgu.getModel()])
|
gfx.text(2, 30, "Model: "..models[cfgu.getModel()])
|
||||||
gfx.text(2, 40, "Language: "..models[cfgu.getLanguage()])
|
gfx.text(2, 40, "Language: "..languages[cfgu.getLanguage()])
|
||||||
gfx.text(2, 50, "Username: "..cfgu.getUsername())
|
gfx.text(2, 50, "Username: "..cfgu.getUsername())
|
||||||
local m,d = cfgu.getBirthday()
|
local m,d = cfgu.getBirthday()
|
||||||
gfx.text(2, 60, "Birthday: "..d.."/"..m)
|
gfx.text(2, 60, "Birthday: "..d.."/"..m)
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,6 @@ Create a HTTP Context.
|
||||||
*/
|
*/
|
||||||
static int httpc_context(lua_State *L) {
|
static int httpc_context(lua_State *L) {
|
||||||
httpcContext context;
|
httpcContext context;
|
||||||
Result ret = httpcOpenContext(&context, "http://google.com/", 0); // Initialization only.
|
|
||||||
if (ret != 0) {
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushinteger(L, ret);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
lua_newuserdata(L, sizeof(&context));
|
lua_newuserdata(L, sizeof(&context));
|
||||||
luaL_getmetatable(L, "LHTTPC");
|
luaL_getmetatable(L, "LHTTPC");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
@ -44,13 +38,25 @@ context object
|
||||||
Open an url in the context.
|
Open an url in the context.
|
||||||
@function :open
|
@function :open
|
||||||
@tparam string url the url to open
|
@tparam string url the url to open
|
||||||
|
@tparam[opt="GET"] string method method to use; can be `"GET"`, `"POST"`, `"HEAD"`, `"PUT"` or `"DELETE"`
|
||||||
*/
|
*/
|
||||||
static int httpc_open(lua_State *L) {
|
static int httpc_open(lua_State *L) {
|
||||||
httpcContext *context = lua_touserdata(L, 1);
|
httpcContext *context = lua_touserdata(L, 1);
|
||||||
char *url = (char*)luaL_checkstring(L, 2);
|
char *url = (char*)luaL_checkstring(L, 2);
|
||||||
|
char *smethod = (char*)luaL_optstring(L, 3, "GET");
|
||||||
|
HTTPC_RequestMethod method = HTTPC_METHOD_GET; // default to GET
|
||||||
|
if (strcmp(smethod, "POST")) {
|
||||||
|
method = HTTPC_METHOD_POST;
|
||||||
|
} else if (strcmp(smethod, "HEAD")) {
|
||||||
|
method = HTTPC_METHOD_HEAD;
|
||||||
|
} else if (strcmp(smethod, "PUT")) {
|
||||||
|
method = HTTPC_METHOD_PUT;
|
||||||
|
} else if (strcmp(smethod, "DELETE")) {
|
||||||
|
method = HTTPC_METHOD_DELETE;
|
||||||
|
}
|
||||||
Result ret = 0;
|
Result ret = 0;
|
||||||
|
|
||||||
ret = httpcOpenContext(context, url, 0);
|
ret = httpcOpenContext(context, method, url, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushinteger(L, ret);
|
lua_pushinteger(L, ret);
|
||||||
|
|
@ -177,6 +183,41 @@ static int httpc_close(lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Add a POST form field to a HTTP context.
|
||||||
|
@function :addPostData
|
||||||
|
@tparam string name name of the field
|
||||||
|
@tparam string value value of the field
|
||||||
|
*/
|
||||||
|
static int httpc_addPostData(lua_State *L) {
|
||||||
|
httpcContext *context = lua_touserdata(L, 1);
|
||||||
|
char *name = (char*)luaL_checkstring(L, 2);
|
||||||
|
char *value = (char*)luaL_checkstring(L, 3);
|
||||||
|
|
||||||
|
httpcAddPostDataAscii(context, name, value);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Get a header field from a response.
|
||||||
|
@function :getResponseHeader
|
||||||
|
@tparam string name name of the header field to get
|
||||||
|
@tparam[opt=2048] number maximum size of the value to get
|
||||||
|
@treturn string field value
|
||||||
|
*/
|
||||||
|
static int httpc_getResponseHeader(lua_State *L) {
|
||||||
|
httpcContext *context = lua_touserdata(L, 1);
|
||||||
|
char *name = (char*)luaL_checkstring(L, 2);
|
||||||
|
u32 maxSize = luaL_checkinteger(L, 3);
|
||||||
|
char* value = 0;
|
||||||
|
|
||||||
|
httpcGetResponseHeader(context, name, value, maxSize);
|
||||||
|
|
||||||
|
lua_pushstring(L, value);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// object
|
// object
|
||||||
static const struct luaL_Reg httpc_methods[] = {
|
static const struct luaL_Reg httpc_methods[] = {
|
||||||
{"open", httpc_open },
|
{"open", httpc_open },
|
||||||
|
|
@ -186,6 +227,8 @@ static const struct luaL_Reg httpc_methods[] = {
|
||||||
{"getDownloadSize", httpc_getDownloadSize },
|
{"getDownloadSize", httpc_getDownloadSize },
|
||||||
{"downloadData", httpc_downloadData },
|
{"downloadData", httpc_downloadData },
|
||||||
{"close", httpc_close },
|
{"close", httpc_close },
|
||||||
|
{"addPostData", httpc_addPostData },
|
||||||
|
{"getResponseHeader", httpc_getResponseHeader },
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -208,7 +251,7 @@ int luaopen_httpc_lib(lua_State *L) {
|
||||||
|
|
||||||
void load_httpc_lib(lua_State *L) {
|
void load_httpc_lib(lua_State *L) {
|
||||||
if (!isHttpcInitialized) {
|
if (!isHttpcInitialized) {
|
||||||
httpcInit();
|
httpcInit(0x1000);
|
||||||
isHttpcInitialized = true;
|
isHttpcInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue