Skip to content

Commit

Permalink
scripting: fix: change default arguments to sol2 overloads
Browse files Browse the repository at this point in the history
- fix scripting on linux (tested on ubuntu 20.1)

- (add overload definitions to the headers to get as close to the real default arguments as possible)
  • Loading branch information
ihm-tswow committed Aug 9, 2021
1 parent c192bf5 commit 330c323
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 20 deletions.
22 changes: 18 additions & 4 deletions src/noggit/scripting/script_brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,24 @@ namespace noggit {
, sol::meta_function::new_index, &script_brush::set
, sol::meta_function::index, &script_brush::get
,"get_name",&script_brush::get_name
,"add_int_tag",&script_brush::add_int_tag
,"add_bool_tag",&script_brush::add_bool_tag
,"add_real_tag",&script_brush::add_real_tag
,"add_string_tag",&script_brush::add_string_tag
,"add_int_tag",sol::overload(
&script_brush::add_int_tag
, &script_brush::add_int_tag_1
, &script_brush::add_int_tag_2
)
,"add_bool_tag",sol::overload(
&script_brush::add_bool_tag
, &script_brush::add_bool_tag_1
)
,"add_real_tag", sol::overload(
&script_brush::add_real_tag
, &script_brush::add_real_tag_1
, &script_brush::add_real_tag_2
)
,"add_string_tag", sol::overload(
&script_brush::add_string_tag
, &script_brush::add_string_tag_1
)
,"add_string_list_tag",&script_brush::add_string_list_tag
,"add_null_tag",&script_brush::add_null_tag
,"add_description",&script_brush::add_description
Expand Down
58 changes: 46 additions & 12 deletions src/noggit/scripting/script_brush.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,64 @@ namespace noggit {
std::string const& item
, int low
, int high
, int def
, bool has_slider = false
, int def /* = low */
, bool has_slider /* = false */
);
std::shared_ptr<int_tag> add_int_tag_1(
std::string const& item
, int low
, int high
, int def
) { return add_int_tag(item,low,high,def, false);}
std::shared_ptr<int_tag> add_int_tag_2(
std::string const& item
, int low
, int high
) { return add_int_tag_1(item,low,high,low);}

std::shared_ptr<real_tag> add_real_tag(std::string const& item
, double low
, double high
, double def
, int zeros = 5
, bool has_slider = false
);
std::shared_ptr<real_tag> add_real_tag(
std::string const& item
, double low
, double high
, double def
, int zeros /* = 5 */
, bool has_slider /* = false */
);
std::shared_ptr<real_tag> add_real_tag_1(
std::string const& item
, double low
, double high
, double def
, int zeros
)
{ return add_real_tag(item,low,high,def,zeros, false); }
std::shared_ptr<real_tag> add_real_tag_2(
std::string const& item
, double low
, double high
, double def
)
{ return add_real_tag_1(item,low,high,def,5); }

std::shared_ptr<string_tag> add_string_tag(
std::string const& item
, std::string const& def);

, std::string const& def /* = "" */
);
std::shared_ptr<string_tag> add_string_tag_1(
std::string const& item)
{ return add_string_tag(item,"");}

std::shared_ptr<string_list_tag> add_string_list_tag(
std::string const& item
, sol::variadic_args va);

std::shared_ptr<bool_tag> add_bool_tag(
std::string const& item
, bool def
, bool def /* = false */
);
std::shared_ptr<bool_tag> add_bool_tag_1(
std::string const& item
) { return add_bool_tag(item,false); }

void add_null_tag();
void add_description(std::string const& text);
Expand Down
5 changes: 4 additions & 1 deletion src/noggit/scripting/script_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ namespace noggit
, "get_texture", &chunk::get_texture
, "get_effect", &chunk::get_effect
, "set_effect", &chunk::set_effect
, "add_texture", &chunk::add_texture
, "add_texture", sol::overload(
&chunk::add_texture
, &chunk::add_texture_1
)
, "clear_textures", &chunk::clear_textures
, "set_hole", &chunk::set_hole
, "clear_colors", &chunk::clear_colors
Expand Down
4 changes: 3 additions & 1 deletion src/noggit/scripting/script_chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ namespace noggit
std::string get_texture(int index);
int get_effect(int index);
void set_effect(int index, int effectID);
int add_texture(std::string const& texture, int effectID = -2);
int add_texture(std::string const& texture, int effectID /* = -2*/);
int add_texture_1(std::string const& texture)
{ return add_texture(texture,-2);}
int get_texture_count();
void clear_textures();
void set_hole(bool hole);
Expand Down
5 changes: 4 additions & 1 deletion src/noggit/scripting/script_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ namespace noggit
, "get_pixel", &image::get_pixel
, "gradient_scale", &image::gradient_scale
, "set_pixel", &image::set_pixel
, "set_pixel_floats", &image::set_pixel_floats
, "set_pixel_floats", sol::overload(
&image::set_pixel_floats
, &image::set_pixel_floats_1
)
, "save", &image::save
, "width", &image::width
, "height", &image::height
Expand Down
6 changes: 5 additions & 1 deletion src/noggit/scripting/script_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ namespace noggit
unsigned get_pixel(int x, int y) const;
float gradient_scale(float rel) const;
void set_pixel(int x, int y, unsigned value);
void set_pixel_floats(int x, int y, float r, float g, float b, float a = 1.0);
void set_pixel_floats(int x, int y, float r, float g, float b, float a /*= 1.0*/);
void set_pixel_floats_1(int x, int y, float r, float g, float b)
{
set_pixel_floats(x,y,r,g,b,1.0);
}
void save(std::string const& filename);
int width() const;
int height() const;
Expand Down

0 comments on commit 330c323

Please sign in to comment.