Пример #1
0
int luaopen_arithmatic (lua_State *L) 
{
    luaA_open(L);
    luaA_struct(L, Complex);
    luaA_struct_member(L, Complex, real_part, float);
    luaA_struct_member(L, Complex, virtual_part, float);

    luaA_function(add_int, int);
    luaA_function(add_complex, Complex, void);

    luaL_openlib(L, "arithmatic", my_arithmatic, 0);
    return 1;
}
Пример #2
0
int dt_lua_init_image(lua_State * L)
{
  luaA_struct(L,dt_image_t);
  luaA_struct_member(L,dt_image_t,exif_exposure,float);
  luaA_struct_member(L,dt_image_t,exif_aperture,float);
  luaA_struct_member(L,dt_image_t,exif_iso,float);
  luaA_struct_member(L,dt_image_t,exif_focal_length,float);
  luaA_struct_member(L,dt_image_t,exif_focus_distance,float);
  luaA_struct_member(L,dt_image_t,exif_crop,float);
  luaA_struct_member(L,dt_image_t,exif_maker,char_64);
  luaA_struct_member(L,dt_image_t,exif_model,char_64);
  luaA_struct_member(L,dt_image_t,exif_lens,char_128);
  luaA_struct_member(L,dt_image_t,exif_datetime_taken,char_20);
  luaA_struct_member(L,dt_image_t,filename,const char_filename_length);
  luaA_struct_member(L,dt_image_t,width,const int32_t);
  luaA_struct_member(L,dt_image_t,height,const int32_t);
  luaA_struct_member(L,dt_image_t,longitude,double);
  luaA_struct_member(L,dt_image_t,latitude,double);

  dt_lua_init_int_type(L,dt_lua_image_t);
  dt_lua_register_type_callback_list(L,dt_lua_image_t,image_index,image_newindex,image_fields_name);
  dt_lua_register_type_callback_type(L,dt_lua_image_t,image_index,image_newindex,dt_image_t);
  dt_lua_register_type_callback_list(L,dt_lua_image_t,colorlabel_index,colorlabel_newindex,dt_colorlabels_name);
  // make these fields read-only by setting a NULL new_index callback
  dt_lua_register_type_callback(L,dt_lua_image_t,image_index,NULL,
      "path", "duplicate_index", "is_ldr", "is_hdr", "is_raw", "id","film","group_leader",
      "apply_style","create_style","reset","move",NULL) ;
  lua_pushcfunction(L,dt_lua_duplicate_image);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"duplicate");
  lua_pushcfunction(L,dt_lua_delete_image);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"delete");
  lua_pushcfunction(L,group_with);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"group_with");
  lua_pushcfunction(L,make_group_leader);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"make_group_leader");
  lua_pushcfunction(L,get_group);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"get_group_members");
  lua_pushcfunction(L,dt_lua_tag_attach);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"attach_tag");
  lua_pushcfunction(L,dt_lua_tag_detach);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"detach_tag");
  lua_pushcfunction(L,dt_lua_tag_get_attached);
  dt_lua_register_type_callback_stack(L,dt_lua_image_t,"get_tags");
  luaL_getmetatable(L,"dt_lua_image_t");
  lua_pushcfunction(L,image_tostring);
  lua_setfield(L,-2,"__tostring");
  lua_pop(L,1);

  return 0;
}
Пример #3
0
int main(int argc, char **argv) {
	
  lua_State* L = luaL_newstate();
  luaA_open();
	
  luaA_conversion(pair, luaA_push_pair, luaA_to_pair);
	
  luaA_struct(L, person_details);
  luaA_struct_member(L, person_details, id, int);
  luaA_struct_member(L, person_details, male, char);
  luaA_struct_member(L, person_details, coolness, float);

  pair p = {1, 2};
  person_details my_details = {0, 1, 125212.213};
  
  luaA_push(L, pair, &p);
  printf("Pair: (%s, %s)\n", lua_tostring(L, -2), lua_tostring(L, -1));
  lua_pop(L, 2);
  
  luaA_push(L, person_details, &my_details);
  
  lua_getfield(L, -1, "id");
  printf("Id: %i\n", (int)lua_tointeger(L, -1));
  lua_pop(L, 1);
  
  lua_getfield(L, -1, "male");
  printf("Male: %s\n", (bool)lua_toboolean(L, -1) ? "true" : "false");
  lua_pop(L, 1);
  
  lua_pop(L, 1);
  
  luaA_close();
  lua_close(L);
	
  return 0;
}
Пример #4
0
int dt_lua_init_image(lua_State *L)
{
  luaA_struct(L, dt_image_t);
  luaA_struct_member(L, dt_image_t, exif_exposure, float);
  luaA_struct_member(L, dt_image_t, exif_aperture, float);
  luaA_struct_member(L, dt_image_t, exif_iso, float);
  luaA_struct_member(L, dt_image_t, exif_focal_length, float);
  luaA_struct_member(L, dt_image_t, exif_focus_distance, float);
  luaA_struct_member(L, dt_image_t, exif_crop, float);
  luaA_struct_member(L, dt_image_t, exif_maker, char_64);
  luaA_struct_member(L, dt_image_t, exif_model, char_64);
  luaA_struct_member(L, dt_image_t, exif_lens, char_128);
  luaA_struct_member(L, dt_image_t, exif_datetime_taken, char_20);
  luaA_struct_member(L, dt_image_t, filename, const char_filename_length);
  luaA_struct_member(L, dt_image_t, width, const int32_t);
  luaA_struct_member(L, dt_image_t, height, const int32_t);
  luaA_struct_member(L, dt_image_t, longitude, protected_double); // set to NAN if value is not set
  luaA_struct_member(L, dt_image_t, latitude, protected_double); // set to NAN if value is not set
  luaA_struct_member(L, dt_image_t, elevation, protected_double); // set to NAN if value is not set

  dt_lua_init_int_type(L, dt_lua_image_t);

  const char *member_name = luaA_struct_next_member_name(L, dt_image_t, LUAA_INVALID_MEMBER_NAME);
  while(member_name != LUAA_INVALID_MEMBER_NAME)
  {
    lua_pushcfunction(L, image_luaautoc_member);
    luaA_Type member_type = luaA_struct_typeof_member_name(L, dt_image_t, member_name);
    if(luaA_conversion_to_registered_type(L, member_type) || luaA_struct_registered_type(L, member_type)
       || luaA_enum_registered_type(L, member_type))
    {
      dt_lua_type_register(L, dt_lua_image_t, member_name);
    }
    else
    {
      dt_lua_type_register_const(L, dt_lua_image_t, member_name);
    }
    member_name = luaA_struct_next_member_name(L, dt_image_t, member_name);
  }

  // read only members
  lua_pushcfunction(L, path_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "path");
  lua_pushcfunction(L, sidecar_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "sidecar");
  lua_pushcfunction(L, duplicate_index_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "duplicate_index");
  lua_pushcfunction(L, is_ldr_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "is_ldr");
  lua_pushcfunction(L, is_hdr_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "is_hdr");
  lua_pushcfunction(L, is_raw_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "is_raw");
  lua_pushcfunction(L, id_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "id");
  lua_pushcfunction(L, film_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "film");
  lua_pushcfunction(L, group_leader_member);
  dt_lua_type_register_const(L, dt_lua_image_t, "group_leader");
  // read/write functions
  lua_pushcfunction(L, has_txt_member);
  dt_lua_type_register(L, dt_lua_image_t, "has_txt");
  lua_pushcfunction(L, rating_member);
  dt_lua_type_register(L, dt_lua_image_t, "rating");
  lua_pushcfunction(L, creator_member);
  dt_lua_type_register(L, dt_lua_image_t, "creator");
  lua_pushcfunction(L, publisher_member);
  dt_lua_type_register(L, dt_lua_image_t, "publisher");
  lua_pushcfunction(L, title_member);
  dt_lua_type_register(L, dt_lua_image_t, "title");
  lua_pushcfunction(L, description_member);
  dt_lua_type_register(L, dt_lua_image_t, "description");
  lua_pushcfunction(L, rights_member);
  dt_lua_type_register(L, dt_lua_image_t, "rights");
  lua_pushcfunction(L, local_copy_member);
  dt_lua_type_register(L, dt_lua_image_t, "local_copy");
  const char **name = dt_colorlabels_name;
  while(*name)
  {
    lua_pushcfunction(L, colorlabel_member);
    dt_lua_type_register(L, dt_lua_image_t, *name);
    name++;
  }
  // constant functions (i.e class methods)
  lua_pushcfunction(L, dt_lua_duplicate_image);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "duplicate");
  lua_pushcfunction(L, dt_lua_delete_image);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "delete");
  lua_pushcfunction(L, group_with);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "group_with");
  lua_pushcfunction(L, make_group_leader);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "make_group_leader");
  lua_pushcfunction(L, get_group);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "get_group_members");
  lua_pushcfunction(L, dt_lua_tag_attach);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "attach_tag");
  lua_pushcfunction(L, dt_lua_tag_detach);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "detach_tag");
  lua_pushcfunction(L, dt_lua_tag_get_attached);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "get_tags");
  lua_pushcfunction(L, dt_lua_style_apply);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "apply_style");
  lua_pushcfunction(L, dt_lua_style_create_from_image);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "create_style");
  lua_pushcfunction(L, history_delete);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "reset");
  lua_pushcfunction(L, dt_lua_move_image);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "move");
  lua_pushcfunction(L, dt_lua_copy_image);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "copy");
  lua_pushcfunction(L, drop_cache);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_lua_image_t, "drop_cache");
  lua_pushcfunction(L, image_tostring);
  dt_lua_type_setmetafield(L,dt_lua_image_t,"__tostring");

  return 0;
}
Пример #5
0
int dt_lua_init_styles(lua_State *L)
{
  // dt_style
  dt_lua_init_type(L, dt_style_t);
  lua_pushcfunction(L, name_member);
  dt_lua_type_register_const(L, dt_style_t, "name");
  lua_pushcfunction(L, description_member);
  dt_lua_type_register_const(L, dt_style_t, "description");
  lua_pushcfunction(L, style_length);
  lua_pushcfunction(L, style_getnumber);
  dt_lua_type_register_number_const(L, dt_style_t);
  lua_pushcfunction(L, style_duplicate);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_style_t, "duplicate");
  lua_pushcfunction(L, style_delete);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_style_t, "delete");
  lua_pushcfunction(L, dt_lua_style_apply);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_style_t, "apply");
  lua_pushcfunction(L, dt_lua_style_export);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const(L, dt_style_t, "export");
  lua_pushcfunction(L, style_gc);
  dt_lua_type_setmetafield(L,dt_style_t,"__gc");
  lua_pushcfunction(L, style_tostring);
  dt_lua_type_setmetafield(L,dt_style_t,"__tostring");

  // dt_style_item_t
  dt_lua_init_type(L, dt_style_item_t);
  luaA_struct(L, dt_style_item_t);
  luaA_struct_member(L, dt_style_item_t, num, const int);
  luaA_struct_member(L, dt_style_item_t, name, const_string);
  lua_pushcfunction(L, dt_lua_type_member_luaautoc);
  dt_lua_type_register_struct(L, dt_style_item_t);
  lua_pushcfunction(L, style_item_gc);
  dt_lua_type_setmetafield(L,dt_style_item_t,"__gc");
  lua_pushcfunction(L, style_item_tostring);
  dt_lua_type_setmetafield(L,dt_style_item_t,"__tostring");



  /* style table type */
  dt_lua_push_darktable_lib(L);
  luaA_Type type_id = dt_lua_init_singleton(L, "style_table", NULL);
  lua_setfield(L, -2, "styles");
  lua_pop(L, 1);

  lua_pushcfunction(L, style_table_len);
  lua_pushcfunction(L, style_table_index);
  dt_lua_type_register_number_const_type(L, type_id);
  lua_pushcfunction(L, style_duplicate);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const_type(L, type_id, "duplicate");
  lua_pushcfunction(L, style_delete);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const_type(L, type_id, "delete");
  lua_pushcfunction(L, dt_lua_style_create_from_image);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const_type(L, type_id, "create");
  lua_pushcfunction(L, dt_lua_style_apply);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const_type(L, type_id, "apply");
  lua_pushcfunction(L, dt_lua_style_import);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const_type(L, type_id, "import");
  lua_pushcfunction(L, dt_lua_style_export);
  lua_pushcclosure(L, dt_lua_type_member_common, 1);
  dt_lua_type_register_const_type(L, type_id, "export");

  return 0;
}