refactor api

pull/81/head
Dibyendu Majumdar 9 years ago
parent 9843f4fdc2
commit 594cfbda90

@ -462,18 +462,45 @@ struct lua_Debug {
LUAI_DDEC int ravi_parser_debug;
LUA_API void ravi_createintegerarray(lua_State *L, int narray,
lua_Integer initial_value);
LUA_API void ravi_createnumberarray(lua_State *L, int narray,
lua_Number initial_value);
/* Create an integer array (specialization of Lua table)
* of given size and initialize array with supplied initial value
*/
LUA_API void ravi_create_integer_array(lua_State *L, int narray,
lua_Integer initial_value);
/* Create an number array (specialization of Lua table)
* of given size and initialize array with supplied initial value
*/
LUA_API void ravi_create_number_array(lua_State *L, int narray,
lua_Number initial_value);
/* Create a slice of an existing array
* The original table containing the array is inserted into the
* the slice as a value against special key so that
* the parent table is not garbage collected while this array contains a
* reference to it
* The array slice starts at start but start-1 is also accessible because of the
* implementation having array values starting at 0.
* A slice must not attempt to release the data array as this is not owned by
* it,
* and in fact may point to garbage from a memory allocater's point of view.
*/
LUA_API void ravi_create_slice(lua_State *L, int idx, unsigned int start,
unsigned int len);
LUA_API int ravi_is_numberarray(lua_State *L, int stackpos);
LUA_API void ravi_get_numberarray_rawdata(lua_State *l, int stackpos, lua_Number **startp, lua_Number **endp);
unsigned int len);
/* Tests if the argument is a number array
*/
LUA_API int ravi_is_number_array(lua_State *L, int idx);
/* Get the raw data associated with the number array at idx.
* Note that Ravi arrays have an extra element at offset 0 - this
* function returns a pointer to &data[0] - bear in mind that
*/
LUA_API lua_Number *ravi_get_number_array_rawdata(lua_State *l, int idx);
LUA_API void ravi_dump_stack(lua_State *L, const char *s);
struct Proto;
LUA_API void ravi_print_function(const struct Proto* f, int full);
LUA_API void ravi_print_function(const struct Proto *f, int full);
LUA_API void ravi_dump_function(lua_State *L);
LUA_API void ravi_set_debuglevel(int level);

@ -741,7 +741,7 @@ LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
/* Create an integer array (specialization of Lua table)
* of given size and initialize array with supplied initial value
*/
LUA_API void ravi_createintegerarray(lua_State *L, int narray,
LUA_API void ravi_create_integer_array(lua_State *L, int narray,
lua_Integer initial_value) {
Table *t;
lua_lock(L);
@ -755,7 +755,7 @@ LUA_API void ravi_createintegerarray(lua_State *L, int narray,
/* Create an number array (specialization of Lua table)
* of given size and initialize array with supplied initial value
*/
LUA_API void ravi_createnumberarray(lua_State *L, int narray,
LUA_API void ravi_create_number_array(lua_State *L, int narray,
lua_Number initial_value) {
Table *t;
lua_lock(L);
@ -766,15 +766,23 @@ LUA_API void ravi_createnumberarray(lua_State *L, int narray,
lua_unlock(L);
}
LUA_API int ravi_is_numberarray(lua_State *L, int idx) {
/* Tests if the argument is a number array
*/
LUA_API int ravi_is_number_array(lua_State *L, int idx) {
StkId o = index2addr(L, idx);
return (ttistable(o) && hvalue(o)->ravi_array.array_type == RAVI_TARRAYFLT ? 1 : 0);
}
LUA_API void ravi_get_numberarray_rawdata(lua_State *L, int idx, lua_Number **startp, lua_Number **endp) {
/* Get the raw data associated with the number array at idx.
* Note that Ravi arrays have an extra element at offset 0 - this
* function returns a pointer to &data[0] - bear in mind that
*/
LUA_API lua_Number* ravi_get_number_array_rawdata(lua_State *L, int idx) {
StkId o = index2addr(L, idx);
lua_assert(ttistable(o) && hvalue(o)->ravi_array.array_type == RAVI_TARRAYFLT);
raviH_get_number_array_rawdata(L, hvalue(o), startp, endp);
double *startp, *endp;
raviH_get_number_array_rawdata(L, hvalue(o), &startp, &endp);
return startp;
}
/* Create a slice of an existing array

@ -335,7 +335,7 @@ static int create_intarray(lua_State *L) {
int n = lua_gettop(L);
lua_Integer init_value = (n == 2 ? luaL_checkinteger(L, 2) : 0);
int size = (int)luaL_checkinteger(L, 1);
ravi_createintegerarray(L, size, init_value);
ravi_create_integer_array(L, size, init_value);
return 1;
}
@ -343,7 +343,7 @@ static int create_fltarray(lua_State *L) {
int n = lua_gettop(L);
lua_Number init_value = (n == 2 ? luaL_checknumber(L, 2) : 0.0);
int size = (int)luaL_checkinteger(L, 1);
ravi_createnumberarray(L, size, init_value);
ravi_create_number_array(L, size, init_value);
return 1;
}

Loading…
Cancel
Save