Skip to content

Commit

Permalink
Get it to work with mruby-yard & to parse typed attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaž Hrastnik committed Jul 14, 2016
1 parent c1664cb commit 4badb20
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ require_relative 'lib/platform'
load 'tasks/mruby.rake'
load 'tasks/shaders.rake'

module YARD::MRuby::Handlers::C::Source
class InitHandler < Base
MATCH3 = /mmrb_\w+_init\s*\(/mx
handles MATCH3
end
end

YARD::Parser::SourceParser.register_parser_type :header, YARD::MRuby::Parser::C::HeaderParser, 'hxx'
YARD::Parser::SourceParser.register_parser_type :source, YARD::MRuby::Parser::C::SourceParser, 'cxx'

YARD::Rake::YardocTask.new do |t|
t.files = %w{modules/**/src/**/mrb_*.cxx modules/**/mrblib/**/*.rb modules/**/include/**/mrb/**/*.hxx}
t.files = %w{modules/system/mrblib/typed_attributes.rb
modules/**/src/**/mrb_*.cxx modules/**/mrblib/**/*.rb modules/**/include/**/mrb/**/*.hxx}
end

task :cmake_clean do
Expand Down
7 changes: 5 additions & 2 deletions modules/graphics/src/mrb_font.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ font_free(mrb_state *mrb, void *p)
MOON_C_API const struct mrb_data_type font_data_type = { "Moon::Font", font_free };

/*
* Font#initialize(filename, size)
* Calculates the string's width and height in pixel using the font.
*
* @param [String] filename Path to the font file
* @param [Integer] font_size Desired font size
*/
static mrb_value
font_initialize(mrb_state *mrb, mrb_value self)
Expand Down Expand Up @@ -67,7 +70,6 @@ font_size(mrb_state *mrb, mrb_value self)
}

/*
* @method Font#calc_bounds
* Calculates the string's width and height in pixel using the font.
*
* @param [String] str
Expand Down Expand Up @@ -104,6 +106,7 @@ font_bind(mrb_state *mrb, mrb_value self)
MOON_C_API void
mmrb_font_init(mrb_state *mrb, struct RClass* mod)
{
struct RClass *mod = mrb_define_module(mrb, "Moon");
struct RClass *font_class = mrb_define_class_under(mrb, mod, "Font", mrb->object_class);
MRB_SET_INSTANCE_TT(font_class, MRB_TT_DATA);

Expand Down
1 change: 1 addition & 0 deletions modules/graphics/src/mrb_shader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ shader_s_is_legacy_set(mrb_state *mrb, mrb_value klass)
MOON_C_API void
mmrb_shader_init(mrb_state *mrb, struct RClass* mod)
{
struct RClass *mod = mrb_define_module(mrb, "Moon");
struct RClass *shader_class = mrb_define_class_under(mrb, mod, "Shader", mrb->object_class);
MRB_SET_INSTANCE_TT(shader_class, MRB_TT_DATA);

Expand Down
1 change: 1 addition & 0 deletions modules/graphics/src/mrb_sprite.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ sprite_generate_buffers(mrb_state *mrb, mrb_value self)
MOON_C_API void
mmrb_sprite_init(mrb_state *mrb, struct RClass* mod)
{
struct RClass *mod = mrb_define_module(mrb, "Moon");
struct RClass *sprite_class = mrb_define_class_under(mrb, mod, "Sprite", mrb->object_class);
mrb_define_method(mrb, sprite_class, "generate_buffers", sprite_generate_buffers, MRB_ARGS_NONE());
}
3 changes: 2 additions & 1 deletion modules/graphics/src/mrb_text.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "moon/mrb/helpers.hxx"

/**
* @method Font#add_text(text, x, y)
* Font#add_text(text, x, y)
*/
static mrb_value
text_add_text(mrb_state *mrb, mrb_value self)
Expand Down Expand Up @@ -46,6 +46,7 @@ text_add_text(mrb_state *mrb, mrb_value self)
MOON_C_API void
mmrb_text_init(mrb_state *mrb, struct RClass* mod)
{
struct RClass *mod = mrb_define_module(mrb, "Moon");
struct RClass *text_cls = mrb_define_class_under(mrb, mod, "Text", mrb->object_class);

mrb_define_method(mrb, text_cls, "add_text", text_add_text, MRB_ARGS_REQ(3));
Expand Down
1 change: 1 addition & 0 deletions modules/graphics/src/mrb_vertex_buffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ vbo_add_quad_vertices(mrb_state *mrb, mrb_value self)
MOON_C_API void
mmrb_vbo_init(mrb_state *mrb, struct RClass* mod)
{
struct RClass *mod = mrb_define_module(mrb, "Moon");
struct RClass *vbo_class = mrb_define_class_under(mrb, mod, "VertexBuffer", mrb->object_class);
MRB_SET_INSTANCE_TT(vbo_class, MRB_TT_DATA);

Expand Down
3 changes: 3 additions & 0 deletions modules/system/mrblib/typed_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module TypedAttributes
# @param [Symbol] name
# @param [Array<Class>] klasses
# @return [Symbol] attribute name
# @!macro [attach] attribute
# @!attribute $1
# @return [$2] Returns the value of attribute $1.
def attribute(name, *klasses)
attr_reader name
varname = "@#{name}"
Expand Down
1 change: 1 addition & 0 deletions modules/system/src/mrb_matrix4.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ matrix4_s_ortho(mrb_state *mrb, mrb_value self)
MOON_C_API void
mmrb_matrix4_init(mrb_state *mrb, struct RClass* mod)
{
// struct RClass *mod = mrb_define_module(mrb, "Moon");
struct RClass *matrix4_class = mrb_define_class_under(mrb, mod, "Matrix4", mrb->object_class);
MRB_SET_INSTANCE_TT(matrix4_class, MRB_TT_DATA);

Expand Down
1 change: 1 addition & 0 deletions modules/system/src/mrb_rect.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ rect_get_h(mrb_state *mrb, mrb_value self)
MOON_C_API void
mmrb_rect_init(mrb_state *mrb, struct RClass *mod)
{
struct RClass *mod = mrb_define_module(mrb, "Moon");
struct RClass *rect_class = mrb_define_class_under(mrb, mod, "Rect", mrb->object_class);
MRB_SET_INSTANCE_TT(rect_class, MRB_TT_DATA);

Expand Down

0 comments on commit 4badb20

Please sign in to comment.