void *lua_new(void) { struct lua *lua = (struct lua *)malloc(sizeof *lua); lua->A = allocator_new(); lua->L = lua_newstate(pixel_lalloc, lua->A); lua->ctx = 0; return lua; }
static ast_t *ast_make(enum AST_TYPE type, allocator_t *al) { ast_t *out; if(al == NULL) { out = malloc(sizeof(ast_t)); } else { out = allocator_new(al, sizeof(ast_t)); } out->type = type; return out; }
static ssize_t data_allocator_fixed_t_convert_from(data_t *data, fastcall_convert_from *fargs){ // {{{ ssize_t ret; if(fargs->src == NULL) return -EINVAL; switch(fargs->format){ case FORMAT(hash):; hash_t *config; data_get(ret, TYPE_HASHT, config, fargs->src); if(ret != 0) return -EINVAL; return allocator_new((allocator_fixed_t **)&data->ptr, config); default: break; }; return -ENOSYS; } // }}}
const char *string_copy_n(const char *str, size_t n, allocator_t *al) { //TODO: check str is valid. size_t len = strlen(str); if(len > n) { len = n; } char *out; if(al == NULL) { out = malloc(len + 1); //TODO: error checking for malloc } else { out = allocator_new(al, len + 1); } memcpy(out, str, len); out[len] = '\0'; return out; }