Skip to content

Commit

Permalink
Documented the HTTPC library, and maybe fixed it (couldn't test, sorry)
Browse files Browse the repository at this point in the history
  • Loading branch information
firew0lf committed Sep 20, 2015
1 parent b47634f commit a3ab825
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion source/httpc.c
@@ -1,3 +1,8 @@
/***
The `httpc` module.
@module ctr.httpc
@usage local httpc = require("ctr.httpc")
*/
#include <stdlib.h>
#include <string.h>

Expand All @@ -8,6 +13,11 @@
#include <lapi.h>
#include <lauxlib.h>

/***
Create a HTTP Context.
@function context
@treturn context a new http context
*/
static int httpc_context(lua_State *L) {
httpcContext context;
Result ret = httpcOpenContext(&context, "http://google.com/", 0); // Initialization only.
Expand All @@ -23,6 +33,16 @@ static int httpc_context(lua_State *L) {
return 1;
}

/***
context object
@section Methods
*/

/***
Open an url in the context.
@function :open
@tparam string url the url to open
*/
static int httpc_open(lua_State *L) {
httpcContext *context = lua_touserdata(L, 1);
char *url = (char*)luaL_checkstring(L, 2);
Expand All @@ -38,6 +58,10 @@ static int httpc_open(lua_State *L) {
return 1;
}

/***
Begin a request to get the content at the URL.
@function :beginRequest
*/
static int httpc_beginRequest(lua_State *L) {
httpcContext *context = lua_touserdata(L, 1);
Result ret = 0;
Expand All @@ -52,6 +76,11 @@ static int httpc_beginRequest(lua_State *L) {
return 1;
}

/***
Return the status code returned by the request.
@function :getStatusCode
@treturn number the status code
*/
static int httpc_getStatusCode(lua_State *L) {
httpcContext *context = lua_touserdata(L, 1);
u32 statusCode = 0;
Expand All @@ -66,6 +95,11 @@ static int httpc_getStatusCode(lua_State *L) {
return 1;
}

/***
Return the amount of data to download.
@function :getDownloadSize
@treturn number size in (bytes)
*/
static int httpc_getDownloadSize(lua_State *L) {
httpcContext *context = lua_touserdata(L, 1);
u32 contentSize = 0;
Expand All @@ -76,6 +110,11 @@ static int httpc_getDownloadSize(lua_State *L) {
return 1;
}

/***
Download and return the data of the context.
@function :downloadData
@treturn string data
*/
static int httpc_downloadData(lua_State *L) {
httpcContext *context = lua_touserdata(L, 1);
u32 status = 0;
Expand All @@ -98,11 +137,15 @@ static int httpc_downloadData(lua_State *L) {
}

lua_pushstring(L, (char*)buff);
free(buff);
//free(buff);
lua_pushinteger(L, size); // only for test purposes.
return 2;
}

/***
Close the context.
@function :close
*/
static int httpc_close(lua_State *L) {
httpcContext *context = lua_touserdata(L, 1);

Expand Down

0 comments on commit a3ab825

Please sign in to comment.