Skip to content

Commit

Permalink
fix(plugin): codegen default values, ref #149
Browse files Browse the repository at this point in the history
  • Loading branch information
iboB committed Nov 22, 2024
1 parent 99ad9de commit 87ed89d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions schema/code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#
add_library(ac-schema INTERFACE)
add_library(ac::schema ALIAS ac-schema)
set_target_properties(ac-schema PROPERTIES
EXPORT_NAME ac::schema
)
target_link_libraries(ac-schema INTERFACE
ac::astl
ac::dict
Expand All @@ -20,6 +23,6 @@ install(TARGETS ac-schema
set(GENERATE_CXX_SCHEMA_RB ${CMAKE_CURRENT_SOURCE_DIR}/generate-cpp-for-ac-model-schema.rb
CACHE INTERNAL "Path to generate-cpp-for-ac-model-schema.rb"
)
install(PROGRAMS generate-cpp-for-ac-model-schema.rb
DESTINATION bin
install(FILES generate-cpp-for-ac-model-schema.rb
DESTINATION opt/alpaca-core/codegen
)
16 changes: 12 additions & 4 deletions schema/code/generate-cpp-for-ac-model-schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#
require 'yaml'

CASE_SPLIT = /[ _\-]/

class String
def pascal_case = split('_').map(&:capitalize).join
def pascal_case = split(CASE_SPLIT).map(&:capitalize).join
def camel_case
first, *rest = split('_')
first, *rest = split(CASE_SPLIT)
first + rest.map(&:capitalize).join
end
end
Expand Down Expand Up @@ -97,14 +99,20 @@ def generate_struct(lines, name, data, indent)
props.each do |pr|
lines << "#{indent} // #{pr[:desc]}" if pr[:desc]
decl = "#{indent} #{pr[:cpp_decl_type]} #{pr[:cpp_name]}"
decl += " = #{pr[:default]}" if pr[:default]
if pr[:default]
if pr[:type] == :array
decl += " = {#{pr[:default].map(&:inspect).join(', ')}}"
else
decl += " = #{pr[:default].inspect}"
end
end
decl += ';'
lines << decl
end

lines << ''

lines << "#{indent} static #{name.pascal_case} fromDict(Dict& dict) {"
lines << "#{indent} static #{name.pascal_case} fromDict([[maybe_unused]] Dict& dict) {"
lines << "#{indent} #{name.pascal_case} ret;"
props.each do |pr|
lines << ''
Expand Down

0 comments on commit 87ed89d

Please sign in to comment.