From 2c30268bf2d60267f4daba0b505f4c0ce0f3751f Mon Sep 17 00:00:00 2001 From: Stephen Berry Date: Wed, 22 Nov 2017 14:05:09 -0600 Subject: [PATCH 1/8] Improved parsing speed of parse_num --- include/chaiscript/chaiscript_defines.hpp | 86 +++++++++++++---------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index 5b2e84f4..3157f429 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -166,48 +166,56 @@ namespace chaiscript { } - template + template auto parse_num(const char *t_str) -> typename std::enable_if::value, T>::type { - T t = 0; - T base = 0; - T decimal_place = 0; - bool exponent = false; - bool neg_exponent = false; + T t = 0; + T base; + T decimal_place = 0; + int exponent = 0; - const auto final_value = [](const T val, const T baseval, const bool hasexp, const bool negexp) -> T { - if (!hasexp) { - return val; - } else { - return baseval * std::pow(T(10), val*T(negexp?-1:1)); - } - }; - - for(; *t_str != '\0'; ++t_str) { - char c = *t_str; - if (c == '.') { - decimal_place = 10; - } else if (c == 'e' || c == 'E') { - exponent = true; - decimal_place = 0; - base = t; - t = 0; - } else if (c == '-' && exponent) { - neg_exponent = true; - } else if (c == '+' && exponent) { - neg_exponent = false; - } else if (c < '0' || c > '9') { - return final_value(t, base, exponent, neg_exponent); - } else if (decimal_place < T(10)) { - t *= T(10); - t += T(c - '0'); - } else { - t += (T(c - '0') / (T(decimal_place))); - decimal_place *= 10; - } - } - - return final_value(t, base, exponent, neg_exponent); + for (char c;; ++t_str) { + c = *t_str; + switch (c) + { + case '.': + decimal_place = 10; + break; + case 'e': + case 'E': + decimal_place = 0; + base = t; + t = 0; + break; + case '-': + exponent = -1; + break; + case '+': + exponent = 1; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (decimal_place < 10) { + t *= 10; + t += c - '0'; + } + else { + t += (c - '0') / decimal_place; + decimal_place *= 10; + } + break; + default: + return exponent ? base * std::pow(T(10), t * exponent) : t; + } + } } template From bcd01f3b03ff95f3d21a942dd9d6c1dcd5dd397b Mon Sep 17 00:00:00 2001 From: Stephen Berry Date: Wed, 22 Nov 2017 14:51:50 -0600 Subject: [PATCH 2/8] Fixed issue when lacking positive exponent sign --- include/chaiscript/chaiscript_defines.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index 3157f429..4c303307 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -183,6 +183,7 @@ namespace chaiscript { break; case 'e': case 'E': + exponent = 1; decimal_place = 0; base = t; t = 0; @@ -191,7 +192,6 @@ namespace chaiscript { exponent = -1; break; case '+': - exponent = 1; break; case '0': case '1': From 035319bbd006ad09a513968d4a5f2944b5242608 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 26 Nov 2017 22:31:35 -0700 Subject: [PATCH 3/8] Fix "compiled loop" optimization --- include/chaiscript/language/chaiscript_optimizer.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/chaiscript/language/chaiscript_optimizer.hpp b/include/chaiscript/language/chaiscript_optimizer.hpp index 55a19c58..c1edb73a 100644 --- a/include/chaiscript/language/chaiscript_optimizer.hpp +++ b/include/chaiscript/language/chaiscript_optimizer.hpp @@ -392,21 +392,21 @@ namespace chaiscript { const auto &prefix_node = child_at(*for_node, 2); if (child_count(*for_node) == 4 - && eq_node.identifier == AST_Node_Type::Equation + && eq_node.identifier == AST_Node_Type::Assign_Decl && child_count(eq_node) == 2 - && child_at(eq_node, 0).identifier == AST_Node_Type::Var_Decl + && child_at(eq_node, 0).identifier == AST_Node_Type::Id && child_at(eq_node, 1).identifier == AST_Node_Type::Constant && binary_node.identifier == AST_Node_Type::Binary && binary_node.text == "<" && child_count(binary_node) == 2 && child_at(binary_node, 0).identifier == AST_Node_Type::Id - && child_at(binary_node, 0).text == child_at(child_at(eq_node,0), 0).text + && child_at(binary_node, 0).text == child_at(eq_node,0).text && child_at(binary_node, 1).identifier == AST_Node_Type::Constant && prefix_node.identifier == AST_Node_Type::Prefix && prefix_node.text == "++" && child_count(prefix_node) == 1 && child_at(prefix_node, 0).identifier == AST_Node_Type::Id - && child_at(prefix_node, 0).text == child_at(child_at(eq_node,0), 0).text) + && child_at(prefix_node, 0).text == child_at(eq_node,0).text) { const Boxed_Value &begin = dynamic_cast &>(child_at(eq_node, 1)).m_value; const Boxed_Value &end = dynamic_cast &>(child_at(binary_node, 1)).m_value; From dee2ce5c56d20d0078c76cb76c44e8480bafdca9 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 30 Nov 2017 09:47:20 -0700 Subject: [PATCH 4/8] Add failing test for ranged_for with variable --- unittests/ranged_for.chai | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unittests/ranged_for.chai b/unittests/ranged_for.chai index 9ef34fed..4e98d7b9 100644 --- a/unittests/ranged_for.chai +++ b/unittests/ranged_for.chai @@ -18,4 +18,9 @@ for (x : retro(range([1,2,3,4]))) { assert_true(result > .6 && result < .7); +var m=["a": ["t": "val"], "b": ["t": "val"]]; +for (i : m) { + var &ref=i.second["t"]; + print(ref); +} From 56140608ef546ca3f22261e80d0771bc91d9e325 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 30 Nov 2017 10:06:32 -0700 Subject: [PATCH 5/8] Fix scope optimizations for ranged for and refs Closes #383 --- include/chaiscript/language/chaiscript_optimizer.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/language/chaiscript_optimizer.hpp b/include/chaiscript/language/chaiscript_optimizer.hpp index c1edb73a..a8118fba 100644 --- a/include/chaiscript/language/chaiscript_optimizer.hpp +++ b/include/chaiscript/language/chaiscript_optimizer.hpp @@ -97,7 +97,7 @@ namespace chaiscript { template bool contains_var_decl_in_scope(const eval::AST_Node_Impl &node) { - if (node.identifier == AST_Node_Type::Var_Decl || node.identifier == AST_Node_Type::Assign_Decl) { + if (node.identifier == AST_Node_Type::Var_Decl || node.identifier == AST_Node_Type::Assign_Decl || node.identifier == AST_Node_Type::Reference) { return true; } @@ -107,6 +107,7 @@ namespace chaiscript { const auto &child = child_at(node, i); if (child.identifier != AST_Node_Type::Block && child.identifier != AST_Node_Type::For + && child.identifier != AST_Node_Type::Ranged_For && contains_var_decl_in_scope(child)) { return true; } From 136539867c1f790926ec7ee3c05b4f2ddd3fee53 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 30 Nov 2017 10:19:56 -0700 Subject: [PATCH 6/8] Remove outdated vim support Closes #288 --- contrib/vim | 1 + contrib/vim/README.txt | 7 -- contrib/vim/ftdetect/chaiscript.vim | 2 - contrib/vim/indent/chaiscript.vim | 50 --------------- contrib/vim/syntax/chaiscript.vim | 99 ----------------------------- 5 files changed, 1 insertion(+), 158 deletions(-) create mode 100644 contrib/vim delete mode 100644 contrib/vim/README.txt delete mode 100644 contrib/vim/ftdetect/chaiscript.vim delete mode 100644 contrib/vim/indent/chaiscript.vim delete mode 100644 contrib/vim/syntax/chaiscript.vim diff --git a/contrib/vim b/contrib/vim new file mode 100644 index 00000000..0877d674 --- /dev/null +++ b/contrib/vim @@ -0,0 +1 @@ +vim support can be found at https://github.com/ChaiScript/vim-chaiscript diff --git a/contrib/vim/README.txt b/contrib/vim/README.txt deleted file mode 100644 index a79b1e75..00000000 --- a/contrib/vim/README.txt +++ /dev/null @@ -1,7 +0,0 @@ -Install ftdetect, indent and syntax subdirectories to: - -~/.vim/ - -See the vim documentation on this: - -http://vimdoc.sourceforge.net/htmldoc/syntax.html#mysyntaxfile diff --git a/contrib/vim/ftdetect/chaiscript.vim b/contrib/vim/ftdetect/chaiscript.vim deleted file mode 100644 index c4ce5ef2..00000000 --- a/contrib/vim/ftdetect/chaiscript.vim +++ /dev/null @@ -1,2 +0,0 @@ -au BufRead,BufNewFile *.chai set filetype=chaiscript - diff --git a/contrib/vim/indent/chaiscript.vim b/contrib/vim/indent/chaiscript.vim deleted file mode 100644 index 247e1a6e..00000000 --- a/contrib/vim/indent/chaiscript.vim +++ /dev/null @@ -1,50 +0,0 @@ -" Vim indent file -" Language: ChaiScript -" Maintainer: Jason Turner - -" Only load this indent file when no other was loaded. -if exists("b:did_indent") - finish -endif -let b:did_indent = 1 - -setlocal indentexpr=GetChaiScriptIndent() -setlocal autoindent - -" Only define the function once. -if exists("*GetChaiScriptIndent") - finish -endif - -function! GetChaiScriptIndent() - " Find a non-blank line above the current line. - let lnum = prevnonblank(v:lnum - 1) - - " Hit the start of the file, use zero indent. - if lnum == 0 - return 0 - endif - - " Add a 'shiftwidth' after lines that start a block: - " lines containing a { - let ind = indent(lnum) - let flag = 0 - let prevline = getline(lnum) - if prevline =~ '^.*{.*' - let ind = ind + &shiftwidth - let flag = 1 - endif - - " Subtract a 'shiftwidth' after lines containing a { followed by a } - " to keep it balanced - if flag == 1 && prevline =~ '.*{.*}.*' - let ind = ind - &shiftwidth - endif - - " Subtract a 'shiftwidth' on lines ending with } - if getline(v:lnum) =~ '^\s*\%(}\)' - let ind = ind - &shiftwidth - endif - - return ind -endfunction diff --git a/contrib/vim/syntax/chaiscript.vim b/contrib/vim/syntax/chaiscript.vim deleted file mode 100644 index b442aaa9..00000000 --- a/contrib/vim/syntax/chaiscript.vim +++ /dev/null @@ -1,99 +0,0 @@ -" Vim syntax file -" Language: ChaiScript -" Maintainer: Jason Turner - -" Quit when a (custom) syntax file was already loaded -if exists("b:current_syntax") - finish -end - -let s:cpo_save = &cpo -set cpo&vim - -syn case match - -" syncing method -syn sync fromstart - -" Strings -syn region chaiscriptString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=chaiscriptSpecial,chaiscriptEval,@Spell - -" Escape characters -syn match chaiscriptSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}" - -" String evals -syn region chaiscriptEval contained start="${" end="}" - -" integer number -syn match chaiscriptNumber "\<\d\+\>" - -" floating point number, with dot, optional exponent -syn match chaiscriptFloat "\<\d\+\.\d*\%(e[-+]\=\d\+\)\=\>" - -" floating point number, starting with a dot, optional exponent -syn match chaiscriptFloat "\.\d\+\%(e[-+]\=\d\+\)\=\>" - -" floating point number, without dot, with exponent -syn match chaiscriptFloat "\<\d\+e[-+]\=\d\+\>" - -" Hex strings -syn match chaiscriptNumber "\<0x\x\+\>" - -" Binary strings -syn match chaiscriptNumber "\<0b[01]\+\>" - -" Various language features -syn keyword chaiscriptCond if else -syn keyword chaiscriptRepeat while for do -syn keyword chaiscriptStatement break continue return switch case default -syn keyword chaiscriptExceptions try catch throw - -"Keyword -syn keyword chaiscriptKeyword def true false attr - -"Built in types -syn keyword chaiscriptType fun var auto - -"Built in funcs, keep it simple -syn keyword chaiscriptFunc eval throw - -"Let's treat all backtick operator function lookups as built in too -syn region chaiscriptFunc matchgroup=chaiscriptFunc start="`" end="`" - -" Account for the "[1..10]" syntax, treating it as an operator -" Intentionally leaving out all of the normal, well known operators -syn match chaiscriptOperator "\.\." - -" Guard seperator as an operator -syn match chaiscriptOperator ":" - -" Comments -syn match chaiscriptComment "//.*$" contains=@Spell -syn region chaiscriptComment matchgroup=chaiscriptComment start="/\*" end="\*/" contains=@Spell - - - -hi def link chaiscriptExceptions Exception -hi def link chaiscriptKeyword Keyword -hi def link chaiscriptStatement Statement -hi def link chaiscriptRepeat Repeat -hi def link chaiscriptString String -hi def link chaiscriptNumber Number -hi def link chaiscriptFloat Float -hi def link chaiscriptOperator Operator -hi def link chaiscriptConstant Constant -hi def link chaiscriptCond Conditional -hi def link chaiscriptFunction Function -hi def link chaiscriptComment Comment -hi def link chaiscriptTodo Todo -hi def link chaiscriptError Error -hi def link chaiscriptSpecial SpecialChar -hi def link chaiscriptFunc Identifier -hi def link chaiscriptType Type -hi def link chaiscriptEval Special - -let b:current_syntax = "chaiscript" - -let &cpo = s:cpo_save -unlet s:cpo_save -" vim: nowrap sw=2 sts=2 ts=8 noet From e78f8a73f966d987faa1e9cb13a0a7fd62f9f5e1 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 4 Dec 2017 19:55:38 -0700 Subject: [PATCH 7/8] Add .clang-format file --- .clang-format | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..65317ab1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,107 @@ +IndentWidth: 2 +UseTab: Never + +AccessModifierOffset: -2 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: TopLevelDefinitions +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyNamespace: true + SplitEmptyRecord: true +BreakAfterJavaFieldAnnotations: false +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Allman +BreakBeforeInheritanceComma: true +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: BeforeComma +BreakConstructorInitializersBeforeComma: true +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 5 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: false +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: true +FixNamespaceComments: false +ForEachMacros: +- foreach +- Q_FOREACH +- BOOST_FOREACH +IncludeCategories: +- Priority: 2 + Regex: ^"(llvm|llvm-c|clang|clang-c)/ +- Priority: 3 + Regex: ^(<|"(gtest|gmock|isl|json)/) +- Priority: 1 + Regex: .* +IncludeIsMainRegex: (Test)?$ +IndentCaseLabels: false +IndentWrappedFunctionNames: false +JavaScriptQuotes: Single +JavaScriptWrapImports: false +KeepEmptyLinesAtTheStartOfBlocks: true +Language: Cpp +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: Inner +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: false +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 23 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 104 +PenaltyBreakString: 916 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 80 +PointerAlignment: Left +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: true +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never + From 6c18c64270b790437d4876d637d08115cc7064ee Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 16 Dec 2017 10:21:02 -0700 Subject: [PATCH 8/8] Formatting updates --- .clang-format | 67 ++++++++++++++++++++++----------------------------- cheatsheet.md | 12 ++++----- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/.clang-format b/.clang-format index 65317ab1..d0c095e1 100644 --- a/.clang-format +++ b/.clang-format @@ -1,59 +1,56 @@ -IndentWidth: 2 -UseTab: Never - AccessModifierOffset: -2 AlignAfterOpenBracket: DontAlign AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignEscapedNewlines: Left -AlignOperands: false +AlignOperands: true AlignTrailingComments: false -AllowAllParametersOfDeclarationOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: true AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Inline +AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: false +AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: TopLevelDefinitions +AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: true -BinPackArguments: true -BinPackParameters: true +AlwaysBreakTemplateDeclarations: false +BinPackArguments: false +BinPackParameters: false BraceWrapping: - AfterClass: false + AfterClass: true AfterControlStatement: false AfterEnum: false AfterFunction: true AfterNamespace: false AfterObjCDeclaration: false - AfterStruct: false + AfterStruct: true AfterUnion: false BeforeCatch: false BeforeElse: false IndentBraces: false - SplitEmptyFunction: true + SplitEmptyFunction: false SplitEmptyNamespace: true SplitEmptyRecord: true -BreakAfterJavaFieldAnnotations: false -BreakBeforeBinaryOperators: All -BreakBeforeBraces: Allman +BreakAfterJavaFieldAnnotations: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom BreakBeforeInheritanceComma: true -BreakBeforeTernaryOperators: false -BreakConstructorInitializers: BeforeComma -BreakConstructorInitializersBeforeComma: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakConstructorInitializersBeforeComma: false BreakStringLiterals: true ColumnLimit: 0 CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: true +CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 5 +ConstructorInitializerIndentWidth: 2 ContinuationIndentWidth: 2 Cpp11BracedListStyle: false DerivePointerAlignment: true DisableFormat: false ExperimentalAutoDetectBinPacking: true -FixNamespaceComments: false +FixNamespaceComments: true ForEachMacros: - foreach - Q_FOREACH @@ -67,38 +64,32 @@ IncludeCategories: Regex: .* IncludeIsMainRegex: (Test)?$ IndentCaseLabels: false -IndentWrappedFunctionNames: false -JavaScriptQuotes: Single -JavaScriptWrapImports: false +IndentWidth: 2 +IndentWrappedFunctionNames: true +JavaScriptQuotes: Leave +JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true Language: Cpp MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 2 NamespaceIndentation: Inner -ObjCBlockIndentWidth: 4 +ObjCBlockIndentWidth: 7 ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: false -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 23 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 104 -PenaltyBreakString: 916 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 80 -PointerAlignment: Left +PointerAlignment: Right ReflowComments: true SortIncludes: false SortUsingDeclarations: false -SpaceAfterCStyleCast: true +SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 +SpacesBeforeTrailingComments: 0 SpacesInAngles: false SpacesInCStyleCastParentheses: false -SpacesInContainerLiterals: false +SpacesInContainerLiterals: true SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 diff --git a/cheatsheet.md b/cheatsheet.md index 28debbca..266ddc71 100644 --- a/cheatsheet.md +++ b/cheatsheet.md @@ -5,7 +5,7 @@ ChaiScript tries to follow the [Semantic Versioning](http://semver.org/) scheme. * Major Version Number: API changes / breaking changes * Minor Version Number: New Features * Patch Version Number: Minor changes / enhancements - + # Initializing ChaiScript @@ -37,7 +37,7 @@ chai.add(chaiscript::fun(&Class::method_name, Class_instance_ptr), "method_name" chai.add(chaiscript::fun(&Class::member_name, Class_instance_ptr), "member_name"); ``` -### With Overloads +### With Overloads #### Preferred @@ -69,9 +69,9 @@ chai.add(chaiscript::fun(static_cast(&Derived::data)), "data"); ``` chai.add( chaiscript::fun( - [](bool type) { - if (type) { return "x"; } - else { return "y"; } + [](bool type) { + if (type) { return "x"; } + else { return "y"; } }), "function_name"); ``` @@ -168,7 +168,7 @@ chai.set_global(chaiscript::var(somevar), "somevar"); // global non-const, overw ## Adding Namespaces -Namespaces will not be populated until `import` is called. +Namespaces will not be populated until `import` is called. This saves memory and computing costs if a namespace is not imported into every ChaiScript instance. ``` chai.register_namespace([](chaiscript::Namespace& math) {