├── .cproject ├── .gitignore ├── .project ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README.md ├── doc ├── .gitignore ├── README.md ├── adoc │ ├── api.adoc │ ├── api_bind_script_function_signature.adoc │ ├── api_byte_code_table.adoc │ ├── api_call_cpp_from_zetscript.adoc │ ├── api_call_zetscript_from_cpp.adoc │ ├── api_data_types.adoc │ ├── api_expose_cpp_type_metamethods.adoc │ ├── api_expose_cpp_type_properties.adoc │ ├── api_expose_cpp_types.adoc │ ├── api_register_const_member_property_signature.adoc │ ├── api_register_function_signature.adoc │ ├── api_register_member_function_signature.adoc │ ├── api_register_member_property_metamethod_names.adoc │ ├── api_register_member_property_metamethod_signature.adoc │ ├── api_stack_element_to_return.adoc │ ├── api_to_stack_element_return.adoc │ ├── introduction.adoc │ ├── language.adoc │ ├── language_class.adoc │ ├── language_class_metamethods.adoc │ ├── language_class_property.adoc │ ├── language_conditionals.adoc │ ├── language_data_types.adoc │ ├── language_function.adoc │ ├── language_literals.adoc │ ├── language_loops.adoc │ ├── language_operators.adoc │ ├── language_standard_library.adoc │ ├── language_variables_and_scopes.adoc │ ├── string_format_format_specifier.adoc │ └── zetscript-reference-manual.adoc ├── examples │ ├── api │ │ ├── bind_script_function │ │ │ ├── bind_script_function.cpp │ │ │ ├── bind_script_function_object_script_function.cpp │ │ │ ├── bind_script_function_param_array_object.cpp │ │ │ ├── bind_script_function_param_bool.cpp │ │ │ ├── bind_script_function_param_const_char.cpp │ │ │ ├── bind_script_function_param_object_object.cpp │ │ │ ├── bind_script_function_param_registered_type.cpp │ │ │ ├── bind_script_function_param_string.cpp │ │ │ ├── bind_script_function_param_string_object.cpp │ │ │ ├── bind_script_function_param_zs_float.cpp │ │ │ ├── bind_script_function_param_zs_int.cpp │ │ │ ├── bind_script_function_return_array_object.cpp │ │ │ ├── bind_script_function_return_bool.cpp │ │ │ ├── bind_script_function_return_class_object.cpp │ │ │ ├── bind_script_function_return_const_char.cpp │ │ │ ├── bind_script_function_return_object_object.cpp │ │ │ ├── bind_script_function_return_registered_type.cpp │ │ │ ├── bind_script_function_return_string.cpp │ │ │ ├── bind_script_function_return_string_object.cpp │ │ │ ├── bind_script_function_return_zs_float.cpp │ │ │ ├── bind_script_function_return_zs_int.cpp │ │ │ └── bind_script_function_string.cpp │ │ ├── build │ │ │ └── file.zs │ │ ├── register_function │ │ │ ├── register_function_param_any.cpp │ │ │ ├── register_function_param_array_script_object.cpp │ │ │ ├── register_function_param_bool.cpp │ │ │ ├── register_function_param_const_char.cpp │ │ │ ├── register_function_param_object_script_object.cpp │ │ │ ├── register_function_param_registered_type.cpp │ │ │ ├── register_function_param_script_function.cpp │ │ │ ├── register_function_param_stack_element.cpp │ │ │ ├── register_function_param_string.cpp │ │ │ ├── register_function_param_string_script_object.cpp │ │ │ ├── register_function_param_zs_float.cpp │ │ │ ├── register_function_param_zs_int.cpp │ │ │ ├── register_function_return_any.cpp │ │ │ ├── register_function_return_array_script_object.cpp │ │ │ ├── register_function_return_bool.cpp │ │ │ ├── register_function_return_class_script_object.cpp │ │ │ ├── register_function_return_object_script_object.cpp │ │ │ ├── register_function_return_registered_type.cpp │ │ │ ├── register_function_return_stack_element.cpp │ │ │ ├── register_function_return_string.cpp │ │ │ ├── register_function_return_string_script_object.cpp │ │ │ ├── register_function_return_zs_float.cpp │ │ │ ├── register_function_return_zs_int.cpp │ │ │ └── registert_function_param_script_function.cpp │ │ ├── register_type │ │ │ ├── Number.h │ │ │ ├── NumberZs.h │ │ │ ├── register_constant_member_property.cpp │ │ │ ├── register_instantiable_type.cpp │ │ │ ├── register_instantiable_type_with_constructor.cpp │ │ │ ├── register_member_function.cpp │ │ │ ├── register_member_metamethod_add.cpp │ │ │ ├── register_member_metamethod_addassign.cpp │ │ │ ├── register_member_metamethod_and.cpp │ │ │ ├── register_member_metamethod_andassign.cpp │ │ │ ├── register_member_metamethod_div.cpp │ │ │ ├── register_member_metamethod_divassign.cpp │ │ │ ├── register_member_metamethod_equ.cpp │ │ │ ├── register_member_metamethod_gt.cpp │ │ │ ├── register_member_metamethod_gte.cpp │ │ │ ├── register_member_metamethod_in.cpp │ │ │ ├── register_member_metamethod_lt.cpp │ │ │ ├── register_member_metamethod_lte.cpp │ │ │ ├── register_member_metamethod_mod.cpp │ │ │ ├── register_member_metamethod_modassign.cpp │ │ │ ├── register_member_metamethod_mul.cpp │ │ │ ├── register_member_metamethod_mulassign.cpp │ │ │ ├── register_member_metamethod_neg.cpp │ │ │ ├── register_member_metamethod_nequ.cpp │ │ │ ├── register_member_metamethod_not.cpp │ │ │ ├── register_member_metamethod_or.cpp │ │ │ ├── register_member_metamethod_orassign.cpp │ │ │ ├── register_member_metamethod_postdec.cpp │ │ │ ├── register_member_metamethod_postinc.cpp │ │ │ ├── register_member_metamethod_predec.cpp │ │ │ ├── register_member_metamethod_preinc.cpp │ │ │ ├── register_member_metamethod_set.cpp │ │ │ ├── register_member_metamethod_shl.cpp │ │ │ ├── register_member_metamethod_shlassign.cpp │ │ │ ├── register_member_metamethod_shr.cpp │ │ │ ├── register_member_metamethod_shrassign.cpp │ │ │ ├── register_member_metamethod_sub.cpp │ │ │ ├── register_member_metamethod_subassign.cpp │ │ │ ├── register_member_metamethod_tostring.cpp │ │ │ ├── register_member_metamethod_xor.cpp │ │ │ ├── register_member_metamethod_xorassign.cpp │ │ │ ├── register_member_property_metamethod_addassign.cpp │ │ │ ├── register_member_property_metamethod_andassign.cpp │ │ │ ├── register_member_property_metamethod_divassign.cpp │ │ │ ├── register_member_property_metamethod_get.cpp │ │ │ ├── register_member_property_metamethod_modassign.cpp │ │ │ ├── register_member_property_metamethod_mulassign.cpp │ │ │ ├── register_member_property_metamethod_orassign.cpp │ │ │ ├── register_member_property_metamethod_postdec.cpp │ │ │ ├── register_member_property_metamethod_postinc.cpp │ │ │ ├── register_member_property_metamethod_predec.cpp │ │ │ ├── register_member_property_metamethod_preinc.cpp │ │ │ ├── register_member_property_metamethod_set.cpp │ │ │ ├── register_member_property_metamethod_shlassign.cpp │ │ │ ├── register_member_property_metamethod_shrassign.cpp │ │ │ ├── register_member_property_metamethod_subassign.cpp │ │ │ ├── register_member_property_metamethod_xorassign.cpp │ │ │ ├── register_non_instantiable_type.cpp │ │ │ ├── register_static_member_function.cpp │ │ │ ├── register_type_inheritance.cpp │ │ │ └── register_type_script_class_extends_from_registered_type.cpp │ │ └── types │ │ │ ├── array_script_object_constructor.cpp │ │ │ ├── array_script_object_element_instance_of.cpp │ │ │ ├── array_script_object_get.cpp │ │ │ ├── array_script_object_length.cpp │ │ │ ├── array_script_object_pop.cpp │ │ │ ├── array_script_object_push.cpp │ │ │ ├── array_script_object_set.cpp │ │ │ ├── array_script_object_to_string.cpp │ │ │ ├── file.zs │ │ │ ├── object_script_object_constructor.cpp │ │ │ ├── object_script_object_element_instance_of.cpp │ │ │ ├── object_script_object_get.cpp │ │ │ ├── object_script_object_get_keys.cpp │ │ │ ├── object_script_object_set.cpp │ │ │ ├── object_script_object_to_string.cpp │ │ │ ├── script_engine_bind_script_function.cpp │ │ │ ├── script_engine_clear.cpp │ │ │ ├── script_engine_compile.cpp │ │ │ ├── script_engine_compile_and_run.cpp │ │ │ ├── script_engine_compile_file.cpp │ │ │ ├── script_engine_compile_file_and_run.cpp │ │ │ ├── script_engine_constructor.cpp │ │ │ ├── script_engine_extends.cpp │ │ │ ├── script_engine_new_array_script_object.cpp │ │ │ ├── script_engine_new_class_script_object.cpp │ │ │ ├── script_engine_new_object_script_object.cpp │ │ │ ├── script_engine_new_string_script_object.cpp │ │ │ ├── script_engine_print_generated_code.cpp │ │ │ ├── script_engine_push_stack_element.cpp │ │ │ ├── script_engine_register_const_member_property.cpp │ │ │ ├── script_engine_register_constant_boolean.cpp │ │ │ ├── script_engine_register_constant_float.cpp │ │ │ ├── script_engine_register_constant_integer.cpp │ │ │ ├── script_engine_register_constant_string.cpp │ │ │ ├── script_engine_register_constructor.cpp │ │ │ ├── script_engine_register_function.cpp │ │ │ ├── script_engine_register_member_function.cpp │ │ │ ├── script_engine_register_member_property_metamethod.cpp │ │ │ ├── script_engine_register_script_type.cpp │ │ │ ├── script_engine_register_static_member_function.cpp │ │ │ ├── script_engine_register_type_instantiable.cpp │ │ │ ├── script_engine_register_type_non_instantiable.cpp │ │ │ ├── script_engine_register_type_non_instantiable_error.cpp │ │ │ ├── script_engine_save_state.cpp │ │ │ ├── script_engine_stack_element_to.cpp │ │ │ ├── script_engine_stack_element_type_to_string.cpp │ │ │ ├── script_engine_stack_element_value_to_string.cpp │ │ │ ├── script_engine_to_stack_element.cpp │ │ │ ├── script_engine_unref_lifetime_object.cpp │ │ │ ├── string_append.cpp │ │ │ ├── string_array_object_length.cpp │ │ │ ├── string_at.cpp │ │ │ ├── string_clear.cpp │ │ │ ├── string_constructor.cpp │ │ │ ├── string_contains.cpp │ │ │ ├── string_ends_with.cpp │ │ │ ├── string_erase.cpp │ │ │ ├── string_find.cpp │ │ │ ├── string_find_last_of.cpp │ │ │ ├── string_format.cpp │ │ │ ├── string_get_substring.cpp │ │ │ ├── string_insert.cpp │ │ │ ├── string_is_empty.cpp │ │ │ ├── string_length.cpp │ │ │ ├── string_operator_access.cpp │ │ │ ├── string_operator_add.cpp │ │ │ ├── string_operator_add_assign.cpp │ │ │ ├── string_operator_assign.cpp │ │ │ ├── string_relational_operators.cpp │ │ │ ├── string_replace.cpp │ │ │ ├── string_script_object_constructor.cpp │ │ │ ├── string_script_object_get.cpp │ │ │ ├── string_script_object_get_const_char.cpp │ │ │ ├── string_script_object_length.cpp │ │ │ ├── string_script_object_set.cpp │ │ │ ├── string_script_object_to_string.cpp │ │ │ ├── string_set_substring.cpp │ │ │ ├── string_split.cpp │ │ │ ├── string_starts_with.cpp │ │ │ ├── string_to_const_char.cpp │ │ │ ├── string_to_lower_case.cpp │ │ │ ├── string_to_upper_case.cpp │ │ │ ├── vector_clear.cpp │ │ │ ├── vector_concat.cpp │ │ │ ├── vector_constructor.cpp │ │ │ ├── vector_data.cpp │ │ │ ├── vector_erase.cpp │ │ │ ├── vector_get.cpp │ │ │ ├── vector_insert.cpp │ │ │ ├── vector_length.cpp │ │ │ ├── vector_operator_assign.cpp │ │ │ ├── vector_pop.cpp │ │ │ ├── vector_push.cpp │ │ │ ├── vector_resize.cpp │ │ │ └── vector_set.cpp │ ├── language │ │ ├── array │ │ │ ├── array_clear.zs │ │ │ ├── array_concat.zs │ │ │ ├── array_contains.zs │ │ │ ├── array_erase_at.zs │ │ │ ├── array_extend.zs │ │ │ ├── array_insert_at.zs │ │ │ ├── array_join.zs │ │ │ ├── array_length.zs │ │ │ ├── array_pop.zs │ │ │ └── array_push.zs │ │ ├── class │ │ │ ├── class_extension.zs │ │ │ ├── class_inicialization_member_methods.zs │ │ │ ├── class_metamethod_add.zs │ │ │ ├── class_metamethod_addassign.zs │ │ │ ├── class_metamethod_and.zs │ │ │ ├── class_metamethod_andassign.zs │ │ │ ├── class_metamethod_bwc.zs │ │ │ ├── class_metamethod_div.zs │ │ │ ├── class_metamethod_divassign.zs │ │ │ ├── class_metamethod_equ.zs │ │ │ ├── class_metamethod_gt.zs │ │ │ ├── class_metamethod_gte.zs │ │ │ ├── class_metamethod_in.zs │ │ │ ├── class_metamethod_iterator.zs │ │ │ ├── class_metamethod_lt.zs │ │ │ ├── class_metamethod_lte.zs │ │ │ ├── class_metamethod_mod.zs │ │ │ ├── class_metamethod_modassign.zs │ │ │ ├── class_metamethod_mul.zs │ │ │ ├── class_metamethod_mulassign.zs │ │ │ ├── class_metamethod_neg.zs │ │ │ ├── class_metamethod_nequ.zs │ │ │ ├── class_metamethod_not.zs │ │ │ ├── class_metamethod_or.zs │ │ │ ├── class_metamethod_orassign.zs │ │ │ ├── class_metamethod_postdec.zs │ │ │ ├── class_metamethod_postinc.zs │ │ │ ├── class_metamethod_predec.zs │ │ │ ├── class_metamethod_preinc.zs │ │ │ ├── class_metamethod_set.zs │ │ │ ├── class_metamethod_shl.zs │ │ │ ├── class_metamethod_shlassign.zs │ │ │ ├── class_metamethod_shr.zs │ │ │ ├── class_metamethod_shrassign.zs │ │ │ ├── class_metamethod_sub.zs │ │ │ ├── class_metamethod_subassign.zs │ │ │ ├── class_metamethod_tostring.zs │ │ │ ├── class_metamethod_xor.zs │ │ │ ├── class_metamethod_xorassign.zs │ │ │ ├── class_property_metamethod_addassign.zs │ │ │ ├── class_property_metamethod_andassign.zs │ │ │ ├── class_property_metamethod_divassign.zs │ │ │ ├── class_property_metamethod_get.zs │ │ │ ├── class_property_metamethod_modassign.zs │ │ │ ├── class_property_metamethod_mulassign.zs │ │ │ ├── class_property_metamethod_orassign.zs │ │ │ ├── class_property_metamethod_postdec.zs │ │ │ ├── class_property_metamethod_postinc.zs │ │ │ ├── class_property_metamethod_predec.zs │ │ │ ├── class_property_metamethod_preinc.zs │ │ │ ├── class_property_metamethod_set.zs │ │ │ ├── class_property_metamethod_shlassign.zs │ │ │ ├── class_property_metamethod_shrassign.zs │ │ │ ├── class_property_metamethod_subassign.zs │ │ │ └── class_property_metamethod_xorassign.zs │ │ ├── console │ │ │ ├── console_error.zs │ │ │ ├── console_errorln.zs │ │ │ ├── console_out.zs │ │ │ └── console_outln.zs │ │ ├── datetime │ │ │ ├── datetime_add_days.zs │ │ │ ├── datetime_add_hours.zs │ │ │ ├── datetime_add_minutes.zs │ │ │ ├── datetime_add_months.zs │ │ │ ├── datetime_add_seconds.zs │ │ │ ├── datetime_add_years.zs │ │ │ ├── datetime_constructor.zs │ │ │ ├── datetime_member_properties.zs │ │ │ ├── datetime_metamethod_sub.zs │ │ │ ├── datetime_now.zs │ │ │ └── datetime_now_utc.zs │ │ ├── float │ │ │ └── float_parse.zs │ │ ├── function │ │ │ ├── function_parameter_by_reference.zs │ │ │ └── function_rest_parameters.zs │ │ ├── integer │ │ │ └── integer_parse.zs │ │ ├── json │ │ │ ├── json_deserialize.zs │ │ │ └── json_serialize.zs │ │ ├── loop │ │ │ ├── loop_break.zs │ │ │ ├── loop_continue.zs │ │ │ ├── loop_do_while.zs │ │ │ ├── loop_for.zs │ │ │ ├── loop_for_in.zs │ │ │ └── loop_while.zs │ │ ├── math │ │ │ ├── math_abs.zs │ │ │ ├── math_ceil.zs │ │ │ ├── math_cos.zs │ │ │ ├── math_deg_to_rad.zs │ │ │ ├── math_floor.zs │ │ │ ├── math_max.zs │ │ │ ├── math_min.zs │ │ │ ├── math_pi.zs │ │ │ ├── math_pow.zs │ │ │ ├── math_random.zs │ │ │ ├── math_round.zs │ │ │ ├── math_sin.zs │ │ │ └── math_sqrt.zs │ │ ├── object │ │ │ ├── object_clear.zs │ │ │ ├── object_concat.zs │ │ │ ├── object_contains.zs │ │ │ ├── object_erase.zs │ │ │ ├── object_extend.zs │ │ │ └── object_keys.zs │ │ ├── string │ │ │ ├── string_append.zs │ │ │ ├── string_clear.zs │ │ │ ├── string_contains.zs │ │ │ ├── string_ends_with.zs │ │ │ ├── string_erase_at.zs │ │ │ ├── string_format.zs │ │ │ ├── string_format_out.zs │ │ │ ├── string_index_of.zs │ │ │ ├── string_insert_at.zs │ │ │ ├── string_length.zs │ │ │ ├── string_replace.zs │ │ │ ├── string_split.zs │ │ │ ├── string_starts_with.zs │ │ │ ├── string_substring.zs │ │ │ ├── string_to_lower_case.zs │ │ │ └── string_to_upper_case.zs │ │ ├── system │ │ │ ├── system_clock.zs │ │ │ └── system_eval.zs │ │ └── type │ │ │ ├── type_instanceof.zs │ │ │ └── type_typeof.zs │ └── make.sh ├── generate-html.sh ├── generate-pdf.sh ├── prefaces │ └── preface_1_historic_version.adoc └── resources │ ├── css │ └── zetscript-reference-manual.css │ ├── js │ └── highlight.min.js │ └── yml │ └── zetscript-reference-manual.yml ├── samples ├── api │ ├── MyClass.h │ ├── MyClassExtend.h │ ├── MyClassExtendZs.h │ ├── MyClassZs.h │ ├── call_script_function.cpp │ ├── helloworld.cpp │ ├── register_class.cpp │ ├── register_constant.cpp │ └── register_function.cpp └── language │ ├── array.zs │ ├── class_metamethod.zs │ ├── class_property.zs │ ├── clock.zs │ ├── datetime.zs │ ├── factorial.zs │ ├── fib.zs │ ├── function_arg_by_ref.zs │ ├── function_arg_default.zs │ ├── helloworld.zs │ ├── if_else.zs │ ├── import.zs │ ├── import │ ├── A.zs │ ├── B.zs │ └── C.zs │ ├── in.zs │ ├── instance_by_value.zs │ ├── instanceof.zs │ ├── json.zs │ ├── loops.zs │ ├── loops_break_continue.zs │ ├── member_function_calls.zs │ ├── object.zs │ ├── prime.zs │ ├── return.zs │ ├── string.zs │ ├── sum.zs │ └── typeof.zs ├── src ├── .gitignore ├── CMakeLists.txt ├── Config.h.in ├── ScriptEngine.cpp ├── ScriptEngine.h ├── ScriptEngine.tcc ├── base │ ├── @base.cpp │ ├── @base.h │ ├── Boolean.cpp │ ├── Boolean.h │ ├── Buffer.cpp │ ├── Buffer.h │ ├── Character.cpp │ ├── Character.h │ ├── Common.h │ ├── Console.cpp │ ├── Console.h │ ├── DateTime.cpp │ ├── DateTime.h │ ├── Directory.cpp │ ├── Directory.h │ ├── Exception.cpp │ ├── Exception.h │ ├── File.cpp │ ├── File.h │ ├── Float.cpp │ ├── Float.h │ ├── Integer.cpp │ ├── Integer.h │ ├── List.h │ ├── List.tcc │ ├── Log.cpp │ ├── Log.h │ ├── MapInt.cpp │ ├── MapInt.h │ ├── MapIntIterator.cpp │ ├── MapIntIterator.h │ ├── MapString.cpp │ ├── MapString.h │ ├── MapStringIterator.cpp │ ├── MapStringIterator.h │ ├── Memory.cpp │ ├── Memory.h │ ├── Path.cpp │ ├── Path.h │ ├── Rtti.cpp │ ├── Rtti.h │ ├── String.cpp │ ├── String.h │ ├── System.cpp │ ├── System.h │ ├── TimeSpan.cpp │ ├── TimeSpan.h │ ├── Vector.h │ └── Vector.tcc ├── compiler │ ├── compiler.cpp │ ├── compiler.h │ ├── compiler_data.cpp │ ├── compiler_expression.cpp │ ├── compiler_expression_byte_code.cpp │ ├── compiler_expression_optimize.cpp │ ├── compiler_expression_token_symbol.cpp │ ├── compiler_keyword.cpp │ ├── compiler_keyword.h │ ├── compiler_keyword_class.cpp │ ├── compiler_keyword_conditional.cpp │ ├── compiler_keyword_function.cpp │ ├── compiler_keyword_loop.cpp │ ├── compiler_keyword_var.cpp │ ├── compiler_object.cpp │ ├── compiler_operator.cpp │ ├── compiler_operator.h │ └── compiler_symbol.cpp ├── core │ ├── @core.cpp │ ├── @core.h │ ├── ByteCode.h │ ├── ByteCodeHelper.cpp │ ├── ByteCodeHelper.h │ ├── Instruction.cpp │ ├── Instruction.h │ ├── MemberProperty.cpp │ ├── MemberProperty.h │ ├── Metamethod.h │ ├── MetamethodHelper.cpp │ ├── MetamethodHelper.h │ ├── MetamethodMembers.cpp │ ├── MetamethodMembers.h │ ├── StackElement.cpp │ ├── StackElement.h │ ├── StackElementMemberProperty.h │ ├── Symbol.cpp │ ├── Symbol.h │ ├── function │ │ ├── FunctionTraits.h │ │ ├── ScriptFunction.cpp │ │ ├── ScriptFunction.h │ │ ├── ScriptFunctionParam.cpp │ │ ├── ScriptFunctionParam.h │ │ ├── ScriptFunctionsFactory.cpp │ │ └── ScriptFunctionsFactory.h │ ├── object │ │ ├── ArrayIteratorScriptObject.cpp │ │ ├── ArrayIteratorScriptObject.h │ │ ├── ArrayIteratorScriptObjectZs.cpp │ │ ├── ArrayIteratorScriptObjectZs.h │ │ ├── ArrayScriptObject.cpp │ │ ├── ArrayScriptObject.h │ │ ├── ArrayScriptObject.tcc │ │ ├── ArrayScriptObjectZs.cpp │ │ ├── ArrayScriptObjectZs.h │ │ ├── ClassScriptObject.cpp │ │ ├── ClassScriptObject.h │ │ ├── ClassScriptObject.tcc │ │ ├── ContainerScriptObject.cpp │ │ ├── ContainerScriptObject.h │ │ ├── ContainerSlot.cpp │ │ ├── ContainerSlot.h │ │ ├── MemberFunctionScriptObject.cpp │ │ ├── MemberFunctionScriptObject.h │ │ ├── ObjectIteratorScriptObject.cpp │ │ ├── ObjectIteratorScriptObject.h │ │ ├── ObjectIteratorScriptObjectZs.cpp │ │ ├── ObjectIteratorScriptObjectZs.h │ │ ├── ObjectScriptObject.cpp │ │ ├── ObjectScriptObject.h │ │ ├── ObjectScriptObject.tcc │ │ ├── ObjectScriptObjectZs.cpp │ │ ├── ObjectScriptObjectZs.h │ │ ├── RefScriptObject.cpp │ │ ├── RefScriptObject.h │ │ ├── ScriptObject.cpp │ │ ├── ScriptObject.h │ │ ├── StringIteratorScriptObject.cpp │ │ ├── StringIteratorScriptObject.h │ │ ├── StringIteratorScriptObjectZs.cpp │ │ ├── StringIteratorScriptObjectZs.h │ │ ├── StringScriptObject.cpp │ │ ├── StringScriptObject.h │ │ ├── StringScriptObjectZs.cpp │ │ ├── StringScriptObjectZs.h │ │ ├── VarRefScriptObject.cpp │ │ └── VarRefScriptObject.h │ ├── scope │ │ ├── ScriptScope.cpp │ │ ├── ScriptScope.h │ │ ├── ScriptScopesFactory.cpp │ │ └── ScriptScopesFactory.h │ └── type │ │ ├── ScriptType.cpp │ │ ├── ScriptType.h │ │ ├── ScriptType.tcc │ │ ├── ScriptTypeId.h │ │ ├── ScriptTypesFactory.cpp │ │ ├── ScriptTypesFactory.h │ │ └── ScriptTypesFactory.tcc ├── module │ ├── @module.cpp │ ├── @module.h │ ├── ConsoleModule.cpp │ ├── ConsoleModule.h │ ├── DateTimeModule.cpp │ ├── DateTimeModule.h │ ├── JsonDeserializeModule.cpp │ ├── JsonModule.cpp │ ├── JsonModule.h │ ├── JsonSerializeModule.cpp │ ├── MathModule.cpp │ ├── MathModule.h │ ├── SystemModule.cpp │ ├── SystemModule.h │ ├── TimeSpanModule.cpp │ └── TimeSpanModule.h ├── vm │ ├── vm.cpp │ ├── vm.h │ ├── vm.tcc │ ├── vm_call.cpp │ ├── vm_call_metamethod.cpp │ ├── vm_common.h │ ├── vm_container.cpp │ ├── vm_iterator.cpp │ ├── vm_native_function.cpp │ ├── vm_new_object.cpp │ ├── vm_operation.h │ ├── vm_operation_assign.h │ ├── vm_pop_stk.h │ ├── vm_push_stk.h │ ├── vm_scope.h │ ├── vm_script_function.cpp │ ├── vm_share_manager.cpp │ ├── vm_share_manager.h │ └── vm_store.cpp ├── zetscript.h └── zs.cpp └── test ├── .gitignore ├── api ├── Number.h ├── NumberZs.h ├── print_object_sizes.cpp ├── test_arithmetic_common.cpp ├── test_arithmetic_common.h ├── test_arithmetic_constants.cpp ├── test_arithmetic_metamethods.cpp ├── test_arithmetic_vars.cpp ├── test_benchmark_std.cpp ├── test_call_native_functions.cpp ├── test_callbacks.cpp ├── test_consecutive_evals.cpp ├── test_perf_warning_native_find.cpp └── test_register_constants.cpp ├── language ├── Number.zs ├── benchmark │ ├── README.md │ ├── binary_trees.wren │ ├── binary_trees.zs │ ├── fib.lua │ ├── fib.nut │ ├── fib.py │ ├── fib.wren │ ├── fib.zs │ ├── for.lua │ ├── for.nut │ ├── for.py │ ├── for.wren │ ├── for.zs │ ├── map_string.lua │ ├── map_string.wren │ ├── map_string.zs │ ├── string_equals.wren │ └── string_equals.zs ├── import │ ├── A.zs │ ├── B.zs │ └── C.zs ├── test_arithmetic_metamethods.zs ├── test_array.zs ├── test_assert_error.zs ├── test_assign.zs ├── test_call.zs ├── test_const.zs ├── test_constant_operations.zs ├── test_cyclic_references.zs ├── test_eval.zs ├── test_extends.zs ├── test_for_in_array.zs ├── test_for_in_object.zs ├── test_for_in_string.zs ├── test_function_arg_by_ref.zs ├── test_function_arg_default.zs ├── test_function_return.zs ├── test_if_else.zs ├── test_import.zs ├── test_in.zs ├── test_instance_from_var_type.zs ├── test_instanceof.zs ├── test_integer_values.zs ├── test_iterator_array.zs ├── test_iterator_metamethod.zs ├── test_iterator_object.zs ├── test_iterator_string.zs ├── test_json.zs ├── test_lexical_scope.zs ├── test_loops.zs ├── test_loops_break_continue.zs ├── test_member_function_call_object_on_unallocated_object.zs ├── test_member_functions.zs ├── test_member_variables.zs ├── test_object.zs ├── test_postinc.zs ├── test_returning_script_object.zs ├── test_string.zs ├── test_switch.zs ├── test_ternary.zs └── test_typeof.zs ├── test_all.cpp └── test_all_config.h.in /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | /.vscode/ 3 | /build/ 4 | /CMakeFiles/ 5 | /bin/ 6 | /src/config.h 7 | CMakeCache.txt 8 | cmake_install.cmake 9 | Makefile 10 | /config.h 11 | /release/ 12 | /debug/ 13 | /Release/ 14 | .pydevproject 15 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeLists.txt 2 | # 3 | # Copyright 2021 by 4 | # Jordi Espada 5 | # 6 | # Say 7 | # 8 | # cmake CMakeLists.txt 9 | # 10 | # to create a Makefile that builds a static version of the library. For a 11 | # dynamic library, use 12 | # 13 | # cmake CMakeLists.txt -DBUILD_SHARED_LIBS:BOOL=true 14 | # 15 | # 16 | # instead. Please refer to the cmake manual for further options, in 17 | # particular, how to modify compilation and linking parameters. 18 | # 19 | 20 | cmake_minimum_required(VERSION 3.15) 21 | 22 | cmake_policy(SET CMP0091 NEW) # To enable MSVC_RUNTIME_LIBRARY. It has effect only when policy CMP0091 is set to NEW prior to the first project() 23 | project(zetscript) 24 | 25 | MESSAGE("-- binary dir:" ${PROJECT_BINARY_DIR} ) 26 | MESSAGE("-- source dir:" ${PROJECT_SOURCE_DIR} ) 27 | 28 | # Recurse into the "src" subdirectories. 29 | add_subdirectory (src) 30 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | *_out.txt 2 | *.exe 3 | *.obj 4 | *.html 5 | *.pdf 6 | examples/api/build 7 | 8 | -------------------------------------------------------------------------------- /doc/adoc/api.adoc: -------------------------------------------------------------------------------- 1 | :highlightjs-languages: cpp, javascript 2 | :sectnums: 3 | 4 | 5 | == The API 6 | 7 | This section aims to explain ZetScript API. It will start by explaining the basic data used in the API. Next sections will be like a tutorial how to call C{plus}{plus} from ZetScript, how to call ZetScript from C{plus}{plus} and finally how to expose native types in ZetScript. 8 | 9 | include::api_data_types.adoc[] 10 | //include::api_eval.adoc[] 11 | include::api_call_cpp_from_zetscript.adoc[] 12 | include::api_call_zetscript_from_cpp.adoc[] 13 | include::api_expose_cpp_types.adoc[] 14 | -------------------------------------------------------------------------------- /doc/adoc/api_stack_element_to_return.adoc: -------------------------------------------------------------------------------- 1 | ** bool 2 | ** <> 3 | ** <> 4 | ** <> 5 | ** <> * 6 | ** <> * 7 | ** <> * 8 | ** A pointer of a register type 9 | -------------------------------------------------------------------------------- /doc/adoc/api_to_stack_element_return.adoc: -------------------------------------------------------------------------------- 1 | ** bool 2 | ** <> 3 | ** <> 4 | ** <> 5 | ** <> * 6 | ** <> * 7 | ** <> * 8 | ** A pointer of a register type 9 | -------------------------------------------------------------------------------- /doc/adoc/zetscript-reference-manual.adoc: -------------------------------------------------------------------------------- 1 | = ZetScript 2.1.0 2 | Jordi Espada 3 | v2.0, May 2024 4 | :doctype: book 5 | :toc: 6 | :toclevels: 5 7 | :icons: 8 | :lang: en 9 | :language: zetscript 10 | :sectnums: 11 | :source-highlighter: rouge 12 | 13 | 14 | include::introduction.adoc[] 15 | include::language.adoc[] 16 | include::api.adoc[] 17 | 18 | 19 | 20 | ifdef::backend-docbook[] 21 | [index] 22 | Index 23 | ----- 24 | endif::backend-docbook[] 25 | 26 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | // Evaluates ZetScript function 'sayHelloWorld' that prints a "Hello world" by console 8 | script_engine.compile( 9 | "function sayHelloWorld(){\n" 10 | " Console::outln(\"Hello world\");\n" 11 | "}\n" 12 | ); 13 | 14 | // It binds 'sayHelloWorld' as 'void(void)' 15 | auto sayHelloWorld=script_engine.bindScriptFunction("sayHelloWorld"); 16 | 17 | // Calls ZetScript function 18 | sayHelloWorld(); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_object_script_function.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main() 4 | { 5 | zetscript::ScriptEngine script_engine; 6 | 7 | script_engine.compileAndRun( 8 | "class A{\n" 9 | " print(){\n" 10 | " Console::outln(\"Call from instanced object\")" 11 | " }\n" 12 | "}\n" 13 | "var a=new A();\n" 14 | ); 15 | 16 | auto a_print=script_engine.bindScriptFunction("a.print"); 17 | 18 | a_print(); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_param_bool.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main() 4 | { 5 | zetscript::ScriptEngine script_engine; 6 | 7 | // Evaluates ZetScript function 'paramBoolean' that prints the contents of '_value' 8 | script_engine.compile( 9 | "function paramBoolean(_value){\n" 10 | " Console::outln(\"result : \"+_value);\n" 11 | "}\n" 12 | ); 13 | 14 | // It binds 'paramBoolean' as '(void *)(bool *)' 15 | auto paramBoolean=script_engine.bindScriptFunction("paramBoolean"); 16 | 17 | // Prepare parameter values 18 | bool value=true; 19 | 20 | // Calls binded ZetScript function with parameters 21 | paramBoolean(&value); 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_param_const_char.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Evaluates ZetScript function 'concat' that prints the result of the operation '+' from two arguments 7 | script_engine.compile( 8 | "function printConcat(_value1, _value2){\n" 9 | " Console::outln(\"result : \"+_value1+\" \"+_value2);\n" 10 | "}\n" 11 | ); 12 | // It binds 'concat' as '(void *)(const char *, const char *)' 13 | auto printConcat=script_engine.bindScriptFunction("printConcat"); 14 | 15 | // Calls binded ZetScript function with parameters 16 | printConcat("Hello","World"); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_param_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Evaluates ZetScript function 'concat' that prints the result of the operation '+' from two arguments 7 | script_engine.compileAndRun( 8 | "function printConcat(_value1, _value2){\n" 9 | " Console::outln(\"result : \"+_value1+\" \"+_value2);\n" 10 | "}\n" 11 | ); 12 | 13 | // It binds 'printConcat' as '(void *)(String *, String *)' 14 | auto printConcat=script_engine.bindScriptFunction< 15 | void( 16 | zetscript::String * _value1, zetscript::String * _value2 17 | )>("printConcat"); 18 | 19 | // Prepare param values 20 | zetscript::String value1="Hello"; 21 | zetscript::String value2="World"; 22 | 23 | // Calls ZetScript function by value 24 | printConcat(&value1,&value2); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_param_zs_float.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Evaluates ZetScript function 'printAdd' that prints the result of the operation '+' from two arguments 7 | script_engine.compile( 8 | "function printAdd(_value1,_value2){\n" 9 | " Console::outln(\"result : \"+(_value1 + _value2));\n" 10 | "}\n" 11 | ); 12 | 13 | // It binds 'printAdd' as '(void *)(zs_float, zs_float *)' 14 | auto printAdd=script_engine.bindScriptFunction< 15 | void( 16 | zetscript::zs_float *_value1 17 | ,zetscript::zs_float *_value2 18 | )>("printAdd"); 19 | 20 | // Prepare parameter values 21 | zetscript::zs_float value1=3.5; 22 | zetscript::zs_float value2=10.7; 23 | 24 | // Calls binded ZetScript function with parameters 25 | printAdd(&value1,&value2); 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_param_zs_int.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Evaluates ZetScript function 'add' that prints the result of the operation '+' from two arguments 7 | script_engine.compile( 8 | "function printAdd(_value1,_value2){\n" 9 | " Console::outln(\"result : \"+(_value1 + _value2));\n" 10 | "}\n" 11 | ); 12 | 13 | // It binds 'printAdd' as '(void *)(zs_int, zs_int)' (by value) 14 | auto printAddByValue=script_engine.bindScriptFunction< 15 | void( 16 | zetscript::zs_int _value1 17 | ,zetscript::zs_int _value2 18 | ) 19 | >("printAdd"); 20 | 21 | // Calls binded ZetScript function with parameters by value 22 | printAddByValue(10,10); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_return_bool.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main() 4 | { 5 | zetscript::ScriptEngine script_engine; 6 | 7 | // Evaluates ZetScript function 'returnBoolean' that returns 'Boolean' value 8 | script_engine.compile( 9 | "function returnBoolean(){\n" 10 | " return true;\n" 11 | "}\n" 12 | ); 13 | 14 | // It binds 'returnBoolean' as 'bool(void)' 15 | auto returnBoolean=script_engine.bindScriptFunction("returnBoolean"); 16 | 17 | // Calls ZetScript function and prints return value by console. 18 | printf("result : %s\n",returnBoolean()?"true":"false"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_return_const_char.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main() 4 | { 5 | zetscript::ScriptEngine script_engine; 6 | 7 | // Evaluates ZetScript function 'returnString' that returns 'String' value 8 | script_engine.compile( 9 | "function returnString(){\n" 10 | " return \"Hello World\";\n" 11 | "}\n" 12 | ); 13 | 14 | // It binds 'returnString' as 'const char *(void)' 15 | auto returnString=script_engine.bindScriptFunction("returnString"); 16 | 17 | // Calls ZetScript function and prints return value by console. 18 | printf("result : %s\n",returnString()); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_return_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Evaluates ZetScript function 'returnString' that returns 'String' value 7 | script_engine.compile( 8 | "function returnString(){\n" 9 | " return \"Hello World\";\n" 10 | "}\n" 11 | ); 12 | 13 | // It binds 'returnString' as 'String(void)' 14 | auto returnString=script_engine.bindScriptFunction< 15 | zetscript::String() 16 | >("returnString"); 17 | 18 | // Calls ZetScript function and prints return value by console. 19 | printf("result : %s\n",returnString().toConstChar()); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_return_zs_float.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main() 4 | { 5 | zetscript::ScriptEngine script_engine; 6 | 7 | // Evaluates ZetScript function 'returnFloat' that returns 'Float' value 8 | script_engine.compile( 9 | "function returnFloat(){\n" 10 | " return 10.5;\n" 11 | "}\n" 12 | ); 13 | 14 | // It binds 'returnFloat' as 'zs_float(void)' 15 | auto returnFloat=script_engine.bindScriptFunction("returnFloat"); 16 | 17 | // Calls ZetScript function and prints return value by console. 18 | printf("result : %f\n",returnFloat()); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_return_zs_int.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Evaluates ZetScript function 'returnInteger' that returns 'Integer' value 7 | script_engine.compile( 8 | "function returnInteger(){\n" 9 | " return 10;\n" 10 | "}\n" 11 | ); 12 | 13 | // It binds 'returnInteger' as 'zs_int(void)' 14 | auto returnInteger=script_engine.bindScriptFunction< 15 | zetscript::zs_int() 16 | >("returnInteger"); 17 | 18 | // Calls ZetScript function and prints return value by console. 19 | printf("result : %ld\n",(long int)returnInteger()); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /doc/examples/api/bind_script_function/bind_script_function_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main() 4 | { 5 | zetscript::ScriptEngine script_engine; 6 | 7 | script_engine.compile( 8 | "function add(_a,_b){\n" 9 | " return _a+_b;\n" 10 | "}\n" 11 | ); 12 | 13 | auto add=script_engine.bindScriptFunction< 14 | zetscript::String( 15 | zetscript::String * 16 | ,zetscript::String * 17 | )>("add"); 18 | 19 | zetscript::String s1="Hello"; 20 | zetscript::String s2="World"; 21 | 22 | printf("result : %s\n", add(&s1,&s2).toConstChar()); 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/examples/api/build/file.zs: -------------------------------------------------------------------------------- 1 | function add(_a,_b){ 2 | return _a+_b; 3 | } 4 | var sum=add(10,5); 5 | Console::outln("result : "+sum) -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_any.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void paramAny( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::StackElement *_stack_element 6 | ){ 7 | printf("StackElement passed is type '%s' with value of '%s'\n" 8 | ,_script_engine->stackElementTypeToString(_stack_element).toConstChar() 9 | ,_script_engine->stackElementValueToString(_stack_element).toConstChar() 10 | ); 11 | } 12 | 13 | int main(){ 14 | zetscript::ScriptEngine script_engine; 15 | 16 | // Register C function 17 | script_engine.registerFunction("paramAny",paramAny); 18 | 19 | // Compiles and runs script 20 | script_engine.compileAndRun( 21 | "paramAny(1); // pass Integer value to paramAny\n" 22 | "paramAny(5.2); // pass Float value to paramAny \n" 23 | "paramAny(\"Hello world!\"); // pass String value to paramAny \n" 24 | ); 25 | 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_array_script_object.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // c function expects an array of integers 4 | void paramArrayScriptObject( 5 | zetscript::ScriptEngine *_script_engine 6 | ,zetscript::ArrayScriptObject *_array 7 | ){ 8 | printf("Values in array => "); 9 | for(int i=0; i < _array->length(); i++){ 10 | printf(" %i",(int)_array->get(i)); 11 | } 12 | printf("\n"); 13 | } 14 | 15 | int main(){ 16 | zetscript::ScriptEngine script_engine; 17 | 18 | script_engine.registerFunction("paramArrayScriptObject",paramArrayScriptObject); 19 | 20 | // call c function with string param 21 | script_engine.compileAndRun( 22 | "paramArrayScriptObject([" 23 | " 0,1,2,3,4,5" 24 | "]);" 25 | ); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_bool.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | 4 | void paramBool( 5 | zetscript::ScriptEngine *_script_engine 6 | , bool *_bool 7 | ){ 8 | printf("Result : %s\n",*_bool?"true":"false"); 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | // Register C function 15 | script_engine.registerFunction("paramBool",paramBool); 16 | 17 | // Compiles and runs script 18 | script_engine.compileAndRun( 19 | "paramBool(true);" 20 | ); 21 | 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_const_char.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // c function 4 | void paramString( 5 | zetscript::ScriptEngine *_script_engine 6 | , const char *_string 7 | ){ 8 | printf("Result : '%s' (const char *)\n",_string); 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | script_engine.registerFunction("paramString",paramString); 15 | 16 | // call c function 17 | script_engine.compileAndRun( 18 | "paramString(\"Hello world!\");" 19 | ); 20 | 21 | 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // c function 4 | void paramString( 5 | zetscript::ScriptEngine *_script_engine, zetscript::String *_string 6 | ){ 7 | printf("Result : '%s' (String *)\n",_string->toConstChar()); 8 | } 9 | 10 | int main(){ 11 | zetscript::ScriptEngine script_engine; 12 | 13 | script_engine.registerFunction("paramString",paramString); 14 | 15 | // call c function 16 | script_engine.compileAndRun( 17 | "paramString(\"Hello world!\");" 18 | ); 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_string_script_object.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // c function 4 | void paramString( 5 | zetscript::ScriptEngine *_script_engine 6 | ,zetscript::StringScriptObject *_string 7 | ){ 8 | printf("String : '%s' (StringScriptObject *)\n",_string->get().toConstChar()); 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | script_engine.registerFunction("paramString",paramString); 15 | 16 | // call c function with string param 17 | script_engine.compileAndRun( 18 | "paramString(\"Hello World\");" 19 | ); 20 | 21 | 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_zs_float.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // c function 4 | void funParamFloat( 5 | zetscript::ScriptEngine *_script_engine 6 | ,zetscript::zs_float *_number 7 | ){ 8 | printf("Result : %f\n",*_number); 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | script_engine.registerFunction("funParamFloat",funParamFloat); 15 | 16 | // call c function 17 | script_engine.compileAndRun( 18 | "funParamFloat(10.5);" 19 | ); 20 | 21 | 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_param_zs_int.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // The C function to register that prints the result of adding (_numbe1) + (*_number2) 4 | void add( 5 | zetscript::ScriptEngine *_script_engine 6 | ,zetscript::zs_int _number1 7 | ,zetscript::zs_int *_number2 8 | ){ 9 | printf("Result _number1 + _number2: %ld\n",(long int)_number1 + *_number2); 10 | } 11 | 12 | int main(){ 13 | zetscript::ScriptEngine script_engine; 14 | 15 | // Registers C function 16 | script_engine.registerFunction("add",add); 17 | 18 | // Evaluates the script that calls C function passing '10' and '20' values as arguments 19 | script_engine.compileAndRun( 20 | "add(10,20);" 21 | ); 22 | 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_return_bool.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | bool returnBoolean( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | return true; 7 | } 8 | 9 | int main(){ 10 | 11 | zetscript::ScriptEngine script_engine; 12 | 13 | // Registers function 14 | script_engine.registerFunction("returnBoolean",returnBoolean); 15 | 16 | // // Compiles and runs a script 17 | script_engine.compileAndRun( 18 | "Console::outln(\"result : \"+returnBoolean());" 19 | ); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_return_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::String returnString( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | return "Hello world (String)"; 7 | } 8 | 9 | int main(){ 10 | zetscript::ScriptEngine script_engine; 11 | 12 | // Registers the C function 13 | script_engine.registerFunction("returnString",returnString); 14 | 15 | // // Compiles and runs a script 16 | script_engine.compileAndRun( 17 | "Console::outln(\"result : \"+returnString());" 18 | ); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_return_string_script_object.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // ScriptEngine C++ interface function 4 | zetscript::StringScriptObject *returnString( 5 | zetscript::ScriptEngine *_script_engine 6 | ){ 7 | 8 | // instance new StringScriptObject using ScriptEngine instance 9 | zetscript::StringScriptObject *string=_script_engine->newStringScriptObject(); 10 | 11 | // set string value "Hello world (StringScriptObject)" 12 | string->set("Hello world (StringScriptObject)"); 13 | 14 | return string; 15 | } 16 | 17 | int main(){ 18 | zetscript::ScriptEngine script_engine; 19 | 20 | // Registers the C function 21 | script_engine.registerFunction("returnString",returnString); 22 | 23 | // // Compiles and runs a script 24 | script_engine.compileAndRun( 25 | "Console::outln(\"result : \"+returnString());" 26 | ); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_return_zs_float.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::zs_float returnFloat( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | return 10.5; 7 | } 8 | 9 | int main(){ 10 | zetscript::ScriptEngine script_engine; 11 | 12 | // Registers the C function 13 | script_engine.registerFunction("returnFloat",returnFloat); 14 | 15 | // // Compiles and runs a script 16 | script_engine.compileAndRun( 17 | "Console::outln(\"result : \"+returnFloat());" 18 | ); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /doc/examples/api/register_function/register_function_return_zs_int.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::zs_int returnInteger( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | return 10; 7 | } 8 | 9 | int main(){ 10 | zetscript::ScriptEngine script_engine; 11 | 12 | // Registers the C function 13 | script_engine.registerFunction("returnInteger",returnInteger); 14 | 15 | // // Compiles and runs a script 16 | script_engine.compileAndRun( 17 | "Console::outln(\"result : \"+returnInteger());" 18 | ); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/register_function/registert_function_param_script_function.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // c function 4 | void paramFunction( 5 | zetscript::ScriptEngine *_script_engine 6 | , zetscript::ScriptFunction *_script_function 7 | ){ 8 | // bind script function to be callable from C 9 | auto function=_script_engine->bindScriptFunction(_script_function); 10 | 11 | // call script function 12 | function(); 13 | } 14 | 15 | int main(){ 16 | zetscript::ScriptEngine script_engine; 17 | 18 | script_engine.registerFunction("paramFunction",paramFunction); 19 | 20 | // call c function with string param 21 | script_engine.compileAndRun( 22 | "paramFunction(function(){\n" 23 | " Console::outln(\"Hello world\");\n" 24 | "});" 25 | ); 26 | 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/Number.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | 8 | class Number{ 9 | public: 10 | 11 | float value; 12 | 13 | Number(){ 14 | value=0; 15 | } 16 | 17 | Number(float _value){ 18 | value=_value; 19 | } 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_constant_member_property.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number();\n" 11 | "Console::outln(\"number::MAX_VALUE => {0}\",number::MAX_VALUE)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_instantiable_type.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun("var number=new Number();"); 10 | 11 | return 0; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_instantiable_type_with_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun("var number=new Number(10.5);"); 10 | 11 | return 0; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_function.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(10.5);\n" 11 | "Console::outln(\"number.toInteger() : \"+number.toInteger())\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_add.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(10) + new Number(20) => \" + (new Number(10) + new Number(20)));\n" 11 | "Console::outln(\"new Number(10) + 20 => \" + (new Number(10) + 20));\n" 12 | "Console::outln(\"10 + new Number(20) => \" + (10 + new Number(20)));\n" 13 | ); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_addassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number+=20 => {0}\",number+=20)\n" 12 | "Console::outln(\"number+=new Number(30) => {0}\",number+=new Number(30))\n" 13 | ); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_and.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(0x7) & new Number(0x4) => \" + (new Number(0x7) & new Number(0x04)));\n" 11 | "Console::outln(\"new Number(0x7) & 0x4 => \" + (new Number(0x7) & 0x04));\n" 12 | "Console::outln(\"0x7 & new Number(0x4) => \" + (0x7 & new Number(0x04)));\n" 13 | ); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_andassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(0x7);\n" 11 | "Console::outln(\"number&=0x3 => {0}\",number&=0x3);\n" 12 | "Console::outln(\"number&=new Number(0x1) => {0}\",number&=new Number(0x1));\n" 13 | ); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_div.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(10) / new Number(20) => \" + (new Number(10) / new Number(20)));\n" 11 | "Console::outln(\"new Number(10) / 20 => \" + (new Number(10) / 20));\n" 12 | "Console::outln(\"10 / new Number(20) => \" + (10 / new Number(20)));\n" 13 | ); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_divassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number/=20 => {0}\",number/=20)\n" 12 | "Console::outln(\"number/=new Number(30) => {0}\",number/=new Number(30))\n" 13 | ); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_equ.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(20) == new Number(20) => \"+(new Number(20) == new Number(20)))\n" 11 | "Console::outln(\"new Number(20) == new Number(30) => \"+(new Number(20) == new Number(30)))\n" 12 | ); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_gt.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(20) > new Number(20) => \"+(new Number(20) > new Number(20)))\n" 11 | "Console::outln(\"new Number(40) > new Number(30) => \"+(new Number(40) > new Number(30)))\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_gte.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(10) >= new Number(20) => \"+(new Number(10) >= new Number(20)))\n" 11 | "Console::outln(\"new Number(20) >= new Number(20) => \"+(new Number(20) >= new Number(20)))\n" 12 | "Console::outln(\"new Number(30) >= new Number(20) => \"+(new Number(30) >= new Number(20)))\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_lt.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(20) < new Number(20) => \"+(new Number(20) < new Number(20)))\n" 11 | "Console::outln(\"new Number(20) < new Number(30) => \"+(new Number(20) < new Number(30)))\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_lte.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(10) <= new Number(20) => \"+(new Number(10) <= new Number(20)))\n" 11 | "Console::outln(\"new Number(20) <= new Number(20) => \"+(new Number(20) <= new Number(20)))\n" 12 | "Console::outln(\"new Number(30) <= new Number(20) => \"+(new Number(30) <= new Number(20)))\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_mod.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(10) % new Number(20) => \" + (new Number(10) % new Number(20)));\n" 11 | "Console::outln(\"new Number(10) % 20 => \" + (new Number(10) % 20));\n" 12 | "Console::outln(\"10 % new Number(20) => \" + (10 % new Number(20)));\n" 13 | ); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_modassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(250);\n" 11 | "Console::outln(\"number%=30 => {0}\",number%=30)\n" 12 | "Console::outln(\"number%=new Number(100) => {0}\",number%=new Number(100))\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_mul.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(10) * new Number(20) => \" + (new Number(10) * new Number(20)));\n" 11 | "Console::outln(\"new Number(10) * 20 => \" + (new Number(10) * 20));\n" 12 | "Console::outln(\"10 * new Number(20) => \" + (10 * new Number(20)));\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_mulassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(2);\n" 11 | "Console::outln(\"number*=2 => {0}\",number*=2)\n" 12 | "Console::outln(\"number*=new Number(2) => {0}\",number*=new Number(2))\n" 13 | ); 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_neg.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20)\n" 11 | "Console::outln(\"-number => \"+ (-number))\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_nequ.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(20) != new Number(20) => \"+(new Number(20) != new Number(20)))\n" 11 | "Console::outln(\"new Number(20) != new Number(30) => \"+(new Number(20) != new Number(30)))\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_not.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number()\n" 11 | "if(!number){\n" 12 | " Console::outln(\"Number is empty\") \n" 13 | "}\n" 14 | ); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_or.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(0x1) | new Number(0x2) => \" + (new Number(0x1) | new Number(0x2)));\n" 11 | "Console::outln(\"new Number(0x1) | 0x2 => \" + (new Number(0x1) | 0x2));\n" 12 | "Console::outln(\"0x1 | new Number(0x2) => \" + (0x1 | new Number(0x2)));\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_orassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(0x1);\n" 11 | "Console::outln(\"number|=0x2 => {0}\",number|=0x2)\n" 12 | "Console::outln(\"number|=new Number(0x4) => {0}\",number|=new Number(0x4))\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_postdec.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number-- => {0}\",number--)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_postinc.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "NumberZs.h" 3 | 4 | int main(){ 5 | 6 | zetscript::ScriptEngine script_engine; 7 | 8 | NumberZs_register(&script_engine); 9 | 10 | script_engine.compileAndRun( 11 | "var number=new Number(20);\n" 12 | "Console::outln(\"number++ => {0}\",number++)\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_predec.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "NumberZs.h" 3 | 4 | int main(){ 5 | 6 | zetscript::ScriptEngine script_engine; 7 | 8 | NumberZs_register(&script_engine); 9 | 10 | script_engine.compileAndRun( 11 | "var number=new Number(20);\n" 12 | "Console::outln(\"--number => {0}\",--number)\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_preinc.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "NumberZs.h" 3 | 4 | int main(){ 5 | 6 | zetscript::ScriptEngine script_engine; 7 | 8 | NumberZs_register(&script_engine); 9 | 10 | script_engine.compileAndRun( 11 | "var number=new Number(20);\n" 12 | "Console::outln(\"++number => {0}\",++number)\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_set.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var n=new Number(0);\n" 11 | "Console::outln(\"n=10 => {0}\",n=10)\n" 12 | "Console::outln(\"n=new Number(20) => {0}\",n=new Number(20))\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_shl.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(0x1) << new Number(2) => \" + (new Number(0x1) << new Number(2)));\n" 11 | "Console::outln(\"new Number(0x1) << 2 => \" + (new Number(0x1) << 2));\n" 12 | "Console::outln(\"0x1 << new Number(2) => \" + (0x1 << new Number(2)));\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_shlassign.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "NumberZs.h" 3 | 4 | int main(){ 5 | 6 | zetscript::ScriptEngine script_engine; 7 | 8 | NumberZs_register(&script_engine); 9 | 10 | script_engine.compileAndRun( 11 | "var number=new Number(0x1);\n" 12 | "Console::outln(\"number<<=1 => {0}\",number<<=1)\n" 13 | "Console::outln(\"number<<=new Number(1) => {0} \",number<<=new Number(1))\n" 14 | ); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_shr.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(0x8) >> new Number(2) => \" + (new Number(0x8) >> new Number(2)));\n" 11 | "Console::outln(\"new Number(0x8) >> 2 => \" + (new Number(0x8) >> 2));\n" 12 | "Console::outln(\"0x8 >> new Number(2) => \" + (0x8 >> new Number(2)));\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_shrassign.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "NumberZs.h" 3 | 4 | int main(){ 5 | 6 | zetscript::ScriptEngine script_engine; 7 | 8 | NumberZs_register(&script_engine); 9 | 10 | script_engine.compileAndRun( 11 | "var number=new Number(0x10);\n" 12 | "Console::outln(\"number>>=1 => {0}\",number>>=1)\n" 13 | "Console::outln(\"number>>=new Number(1) => {0}\",number>>=new Number(1))\n" 14 | ); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_sub.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(10) - new Number(20) => \" + (new Number(10) - new Number(20)));\n" 11 | "Console::outln(\"new Number(10) - 20 => \" + (new Number(10) - 20));\n" 12 | "Console::outln(\"10 - new Number(20) => \" + (10 - new Number(20)));\n" 13 | ); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_subassign.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "NumberZs.h" 3 | 4 | int main(){ 5 | 6 | zetscript::ScriptEngine script_engine; 7 | 8 | NumberZs_register(&script_engine); 9 | 10 | script_engine.compileAndRun( 11 | "var number=new Number(20);\n" 12 | "Console::outln(\"number-=20 => {0}\",number-=20)\n" 13 | "Console::outln(\"number-=new Number(30) => {0}\",number-=new Number(30))\n" 14 | ); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_tostring.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"Result _tostring => \"+new Number(10))" 11 | ); 12 | 13 | return 0; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_xor.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"new Number(0xa) ^ new Number(0x9) => \" + (new Number(0xa) ^ new Number(0x9)));\n" 11 | "Console::outln(\"new Number(0xa) ^ 0x9 => \" + (new Number(0xa) ^ 0x9));\n" 12 | "Console::outln(\"0xa ^ new Number(0x9) => \" + (0xa ^ new Number(0x9)));\n" 13 | ); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_metamethod_xorassign.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "NumberZs.h" 3 | 4 | int main(){ 5 | 6 | zetscript::ScriptEngine script_engine; 7 | 8 | NumberZs_register(&script_engine); 9 | 10 | script_engine.compileAndRun( 11 | "var number=new Number(0);\n" 12 | "Console::outln(\"number^=0xa => {0}\",number^=0xa);\n" 13 | "Console::outln(\"number^=new Number(0x9) => {0}\",number^=new Number(0x9))\n" 14 | ); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_addassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number.value+=10 => {0}\",number.value+=10)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_andassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(0xf);\n" 11 | "Console::outln(\"number.value&=0x7 => {0}\",number.value&=0x7)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_divassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number.value/=20 => {0}\",number.value/=20)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_get.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number.value => {0}\",number.value)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_modassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(250);\n" 11 | "Console::outln(\"number.value%=30 => {0}\",number.value%=30)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_mulassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number.value*=2 => {0}\",number.value*=2)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_orassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(0x1);\n" 11 | "Console::outln(\"number.value|=0x2 => {0}\",number.value|=0x2)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_postdec.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number.value-- => {0}\",number.value--)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_postinc.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"number.value++ => {0}\",number.value++)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_predec.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"--number.value => {0}\",--number.value)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_preinc.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"++number.value => {0}\",++number.value)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_set.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(20);\n" 11 | "Console::outln(\"On operation 'number=new Number(20)' then 'number.value' is => \"+number.value)\n" 12 | "number.value = 10;\n" 13 | "Console::outln(\"On operation 'number=10' the 'number.value' is => \"+number.value)\n" 14 | ); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_shlassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(0x1);\n" 11 | "Console::outln(\"number.value<<=1 => {0}\",number.value<<=1)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_shrassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number = new Number(0x8);\n" 11 | "Console::outln(\"number.value>>=1 => {0}\",number.value>>=1)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_subassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(30);\n" 11 | "Console::outln(\"number.value-=20 => {0}\",number.value-=20)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_member_property_metamethod_xorassign.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "var number=new Number(0x0);\n" 11 | "Console::outln(\"number.value^=0xa => {0}\",number.value^=0xa)\n" 12 | ); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_non_instantiable_type.cpp: -------------------------------------------------------------------------------- 1 | #include "Number.h" 2 | #include "zetscript.h" 3 | 4 | // Number reference 5 | Number *number=NULL; 6 | 7 | // function that returns number reference 8 | Number *getNumber( 9 | zetscript::ScriptEngine *_script_engine 10 | ){ 11 | return number; 12 | } 13 | 14 | int main(){ 15 | 16 | zetscript::ScriptEngine script_engine; 17 | 18 | script_engine.registerType("Number"); 19 | 20 | // create new 'Number' 21 | number=new Number(); 22 | 23 | //register function 'getNumber' that return 'number' reference 24 | script_engine.registerFunction("getNumber",getNumber); 25 | 26 | 27 | // Evaluates ZetScript code that calls 'getNumber' to get 'number' object reference 28 | script_engine.compileAndRun( 29 | "var number= getNumber();" 30 | ); 31 | 32 | // delete instance 33 | delete number; 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /doc/examples/api/register_type/register_static_member_function.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberZs.h" 2 | 3 | int main(){ 4 | 5 | zetscript::ScriptEngine script_engine; 6 | 7 | NumberZs_register(&script_engine); 8 | 9 | script_engine.compileAndRun( 10 | "Console::outln(\"Number::pow(2,10) : \"+Number::pow(2,10))" 11 | ); 12 | 13 | return 0; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/api/types/array_script_object_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::ArrayScriptObject *returnNewArrayScriptObject( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | 7 | // instance new StringScriptObject using ScriptEngine instance 8 | zetscript::ArrayScriptObject *array_object=new zetscript::ArrayScriptObject(_script_engine); 9 | 10 | //... 11 | 12 | return array_object; 13 | } 14 | 15 | int main(){ 16 | zetscript::ScriptEngine script_engine; 17 | 18 | // Registers returnNewArrayScriptObject 19 | script_engine.registerFunction("returnNewArrayScriptObject",returnNewArrayScriptObject); 20 | 21 | // prints the contents of new array object (empty) 22 | script_engine.compileAndRun("Console::outln(returnNewArrayScriptObject())"); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/types/array_script_object_length.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void printArrayLength( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::ArrayScriptObject *_array_object 6 | ){ 7 | printf("The length of vector is %i\n",_array_object->length()); 8 | } 9 | 10 | int main(){ 11 | zetscript::ScriptEngine script_engine; 12 | 13 | // registers printArrayLength 14 | script_engine.registerFunction("printArrayLength",printArrayLength); 15 | 16 | // calls printArrayLength 17 | script_engine.compileAndRun("printArrayLength([0,1,2,3])"); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/types/array_script_object_pop.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::ScriptEngine script_engine; 4 | 5 | script_engine.compileAndRun(""); 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /doc/examples/api/types/array_script_object_to_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // print array contents 4 | void printArray( 5 | zetscript::ScriptEngine *_script_engine 6 | ,zetscript::ArrayScriptObject *_array_object 7 | ){ 8 | printf("Array contents : %s",_array_object->toString().toConstChar()); 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | // registers printArray 15 | script_engine.registerFunction("printArray",printArray); 16 | 17 | // calls printArray 18 | script_engine.compileAndRun( 19 | "printArray([" 20 | "0" 21 | ",10.5" 22 | ",\"Hello World!\"" 23 | "])"); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /doc/examples/api/types/file.zs: -------------------------------------------------------------------------------- 1 | function add(_a,_b){ 2 | return _a+_b; 3 | } 4 | var sum=add(10,5); 5 | Console::outln("result : "+sum) -------------------------------------------------------------------------------- /doc/examples/api/types/object_script_object_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::ObjectScriptObject *returnNewObject( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | // instance new StringScriptObject using ScriptEngine instance 7 | zetscript::ObjectScriptObject *new_object=new zetscript::ObjectScriptObject(_script_engine); 8 | 9 | //... 10 | 11 | return new_object; 12 | } 13 | 14 | int main(){ 15 | zetscript::ScriptEngine script_engine; 16 | 17 | // Registers returnNewObject 18 | script_engine.registerFunction("returnNewObject",returnNewObject); 19 | 20 | // prints the contents of new array object (empty) 21 | script_engine.compileAndRun("Console::outln(returnNewObject())"); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /doc/examples/api/types/object_script_object_to_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // print array contents 4 | void printObject( 5 | zetscript::ScriptEngine *_script_engine 6 | ,zetscript::ObjectScriptObject *_object 7 | ){ 8 | printf("ScriptObject contents : %s",_object->toString().toConstChar()); 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | // registers printObject 15 | script_engine.registerFunction("printObject",printObject); 16 | 17 | // calls printObject 18 | script_engine.compileAndRun( 19 | "printObject({" 20 | "\"key1\":0" 21 | ",\"key2\":10.5" 22 | ",\"key3\":\"Hello World!\"" 23 | "})"); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_bind_script_function.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Compiles 'printHelloWorld' function 7 | script_engine.compile("function printHelloWorld(){\n" 8 | "Console::outln(\"Hello world!!\");\n" 9 | "}"); 10 | 11 | // binds 'printHelloWorld' 12 | auto print_hello_world=script_engine.bindScriptFunction("printHelloWorld"); 13 | 14 | // invoke 'printHelloWorld' 15 | print_hello_world(); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_clear.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | script_engine.compileAndRun("var i=10;"); 7 | 8 | // Prints the value of symbol 'i' 9 | script_engine.compileAndRun("Console::outln(\"i => \"+i);"); 10 | 11 | // Clears current state. After clear, symbol 'i' doesn't exist anymore 12 | script_engine.clear(); 13 | 14 | // throws an error that symbol 'i' does not exist 15 | try{ 16 | script_engine.compileAndRun("Console::outln(\"i => \"+i);"); 17 | }catch(zetscript::Exception & ex){ 18 | printf("Error: %s\n",ex.what()); 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_compile.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Compiles function "add" 7 | script_engine.compile( 8 | "function add(_o1,_o2){\n" 9 | " return _o1+_o2;\n" 10 | "}\n" 11 | ); 12 | 13 | // Compiles code that uses "adds" function previusly defined 14 | script_engine.compile( 15 | "var b=add(2,3)\n" 16 | "Console::outln(\"b = \"+b)\n" 17 | ); 18 | 19 | // It runs the code compiled (Prints result of variable 'b') 20 | script_engine.run(); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_compile_and_run.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | 4 | zetscript::ScriptEngine script_engine; 5 | 6 | script_engine.compileAndRun( 7 | "Console::outln(\"Hello world\")" 8 | ); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_compile_file.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::ScriptEngine script_engine; 4 | 5 | script_engine.compileFile("file.zs"); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_compile_file_and_run.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | script_engine.compileFileAndRun("file.zs"); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine(1024); // It reserves 1K for stack size 5 | 6 | // ... 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_new_string_script_object.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::StringScriptObject *returnNewStringScriptObject( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | 7 | // instance new StringScriptObject using ScriptEngine instance 8 | zetscript::StringScriptObject *string_object=_script_engine->newStringScriptObject("Hello World!"); 9 | 10 | // ... 11 | 12 | return string_object; 13 | } 14 | 15 | int main(){ 16 | zetscript::ScriptEngine script_engine; 17 | 18 | // Registers returnNewStringScriptObject 19 | script_engine.registerFunction("returnNewStringScriptObject",returnNewStringScriptObject); 20 | 21 | // prints the returning of new string object 22 | script_engine.compileAndRun("Console::outln(returnNewStringScriptObject())"); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_print_generated_code.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | 4 | zetscript::ScriptEngine script_engine; 5 | 6 | script_engine.compile( 7 | "function sum(_a,_b){\n" 8 | " return _a+_b\n" 9 | "}\n" 10 | "\n" 11 | "Console::outln(\"result: {0}\",sum(5+10))\n" 12 | ); 13 | 14 | script_engine.printGeneratedCode(); 15 | } 16 | -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_const_member_property.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | class Number{ 4 | //... 5 | }; 6 | 7 | zetscript::zs_float NumberZs_MAX_VALUE( 8 | zetscript::ScriptEngine *_script_engine 9 | ){ 10 | ZS_UNUSUED_PARAM(_script_engine); 11 | return FLT_MAX; 12 | } 13 | 14 | 15 | int main(){ 16 | zetscript::ScriptEngine script_engine; 17 | 18 | script_engine.registerType("Number"); 19 | 20 | script_engine.registerConstMemberProperty("MAX_VALUE",NumberZs_MAX_VALUE); 21 | 22 | script_engine.compileAndRun( 23 | 24 | "Console::outln(\"Number::MAX_VALUE => {0}\",Number::MAX_VALUE);" 25 | ); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_constant_boolean.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "zetscript.h" 3 | 4 | int main(){ 5 | 6 | // instance ScriptEngine 7 | zetscript::ScriptEngine script_engine; 8 | 9 | // Registers a constant Boolean 10 | script_engine.registerConstantBoolean("MY_CONSTANT_BOOL",true); 11 | 12 | // Prints the value of each registered constant 13 | script_engine.compileAndRun( 14 | "Console::outln(\"MY_CONSTANT_BOOL:\"+MY_CONSTANT_BOOL);\n" 15 | ); 16 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_constant_float.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "zetscript.h" 3 | 4 | int main(){ 5 | 6 | // instance ScriptEngine 7 | zetscript::ScriptEngine script_engine; 8 | 9 | // Registers a constant Float 10 | script_engine.registerConstantFloat("MY_CONSTANT_FLOAT",2.5e-3); 11 | 12 | // Prints the value of each registered constant 13 | script_engine.compileAndRun( 14 | "Console::outln(\"MY_CONSTANT_FLOAT:\"+MY_CONSTANT_FLOAT);\n" 15 | ); 16 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_constant_integer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "zetscript.h" 3 | 4 | int main(){ 5 | 6 | // instance ScriptEngine 7 | zetscript::ScriptEngine script_engine; 8 | 9 | // Registers a constant Integer 10 | script_engine.registerConstantInteger("MY_CONSTANT_INT",10); 11 | 12 | // Prints the value of each registered constant 13 | script_engine.compileAndRun( 14 | "Console::outln(\"MY_CONSTANT_INT:\"+MY_CONSTANT_INT);\n" 15 | ); 16 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_constant_string.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "zetscript.h" 3 | 4 | int main(){ 5 | 6 | // instance ScriptEngine 7 | zetscript::ScriptEngine script_engine; 8 | 9 | // Registers a constant String 10 | script_engine.registerConstantString("MY_CONSTANT_STR","my_string"); 11 | 12 | // Prints the value of each registered constant 13 | script_engine.compileAndRun( 14 | "Console::outln(\"MY_CONSTANT_STR:\"+MY_CONSTANT_STR);\n" 15 | ); 16 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_function.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | // ScriptEngine C++ interface function 4 | void sayHelloWorld(zetscript::ScriptEngine *_script_engine){ 5 | printf("Hello world\n"); 6 | } 7 | 8 | int main(){ 9 | zetscript::ScriptEngine script_engine; 10 | 11 | // Registers sayHelloWorld as 'sayHelloWorld' symbol name 12 | script_engine.registerFunction("sayHelloWorld",sayHelloWorld); 13 | 14 | // Evaluates a script where it calls 'sayHelloWorld' function 15 | script_engine.compileAndRun( 16 | "sayHelloWorld();" 17 | ); 18 | 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_script_type.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::ScriptEngine script_engine; 4 | 5 | 6 | return 0; 7 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_static_member_function.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | #include 3 | 4 | class Number{ 5 | //... 6 | }; 7 | 8 | zetscript::zs_float NumberZs_pow( 9 | zetscript::ScriptEngine *_script_engine 10 | ,zetscript::zs_float *_base 11 | ,zetscript::zs_float *_exp 12 | ){ 13 | 14 | return pow(*_base,*_exp); 15 | } 16 | 17 | 18 | int main(){ 19 | zetscript::ScriptEngine script_engine; 20 | 21 | script_engine.registerType("Number"); 22 | 23 | script_engine.registerStaticMemberFunction("pow",NumberZs_pow); 24 | 25 | script_engine.compileAndRun( 26 | 27 | "Console::outln(\"Number::pow(2,2) => {0}\",Number::pow(2,2));" 28 | ); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_register_type_non_instantiable_error.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | // Defines MyType 3 | class MyType{ 4 | //... 5 | }; 6 | 7 | int main(){ 8 | zetscript::ScriptEngine script_engine; 9 | 10 | // Registers MyType as not instantiable 11 | script_engine.registerType("MyType"); 12 | 13 | // tries to instance t as MyType where MyType is NOT instantiable 14 | try{ 15 | script_engine.compile("var t=new MyType()"); 16 | }catch(zetscript::Exception & _ex){ 17 | printf("%s\n",_ex.what()); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_save_state.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::ScriptEngine script_engine; 4 | 5 | // declares and initializes variable 'i' 6 | script_engine.compileAndRun("var i=10;"); 7 | 8 | // saves current state, so variable 'i' is saved 9 | script_engine.saveState(); 10 | 11 | // Clears current state. It doesn't clear symbol 'i' because it was saved 12 | script_engine.clear(); 13 | 14 | // prints 'i' after clear state 15 | script_engine.compileAndRun("Console::outln(\"i after clear => \"+i);"); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_stack_element_to.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Returns Object in StackElement as a result of compile and run "return {f1:10,f2:20,f4:40}" 7 | zetscript::StackElement result=script_engine.compileAndRun("return {f1:10,f2:20,f4:40}"); 8 | 9 | // Converts stack element to ObjectScriptObject 10 | zetscript::ObjectScriptObject *result_object=script_engine.stackElementTo(result); 11 | 12 | // ... 13 | // perform some operations with 'result_object' 14 | // ... 15 | 16 | // unref lifetime object due is not needed anymore. 17 | script_engine.unrefLifetimeObject(result_object); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_stack_element_type_to_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void printStackElementType( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::StackElement *_stack_element 6 | ){ 7 | printf("StackElement type is '%s'\n" 8 | ,_script_engine->stackElementTypeToString(_stack_element).toConstChar() 9 | ); 10 | } 11 | 12 | int main(){ 13 | zetscript::ScriptEngine script_engine; 14 | 15 | // Register C function 16 | script_engine.registerFunction("printStackElementType",printStackElementType); 17 | 18 | // Compiles and runs script 19 | script_engine.compileAndRun( 20 | "printStackElementType(1); // pass Integer value to printStackElementType\n" 21 | "printStackElementType(5.2); // pass Float value to printStackElementType \n" 22 | "printStackElementType(\"Hello world!\"); // pass String value to printStackElementType \n" 23 | ); 24 | 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /doc/examples/api/types/script_engine_unref_lifetime_object.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::ScriptEngine script_engine; 5 | 6 | // Eval an expression that returns a 'Object' type as result 7 | auto result=script_engine.compileAndRun("return {f1:10,f2:20,f4:40}"); 8 | 9 | // Converts stack element to ObjectScriptObject 10 | zetscript::ObjectScriptObject *result_object=script_engine.stackElementTo(result); 11 | 12 | // ... 13 | // perform some operations with 'result_object' 14 | // ... 15 | 16 | // unref lifetime object due is not needed anymore. 17 | script_engine.unrefLifetimeObject(result_object); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_append.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::String string; 4 | 5 | string="Hello"; 6 | string.append(" World"); 7 | string.append('!'); 8 | 9 | printf("%s\n",string.toConstChar()); 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_array_object_length.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void checkLengthArray( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::ArrayScriptObject *_array_object 6 | ){ 7 | // instance new ArrayScriptObject using ScriptEngine instance 8 | printf("The length of array is : %i\n",_array_object->length()); 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | // registers modifyArray 15 | script_engine.registerFunction("checkLengthArray",checkLengthArray); 16 | 17 | // create a initialized array, it prints. then prints the 18 | // the array after call 'modifyArray' 19 | script_engine.compileAndRun( 20 | "var v=[0,1.5,\"world\"]\n" 21 | "checkLengthArray(v)\n" 22 | ); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_at.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="Hello World"; 5 | 6 | for(int c=0; c < string.length();c++){ 7 | printf("%c",string.at(c)); 8 | } 9 | 10 | printf("\n"); 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_clear.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="Hello World"; 5 | 6 | string.clear(); 7 | 8 | printf("string : '%s'\n",string.toConstChar()); 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(void){ 4 | 5 | // empty string 6 | zetscript::String empty_string; 7 | 8 | // initialized string 9 | zetscript::String string=zetscript::String("Hello world"); 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_contains.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | 5 | zetscript::String s="The quick brown fox jumps over the lazy dog."; 6 | 7 | printf("s.contains(\"fo\") => '%s'\n",s.contains("fo")?"true":"false"); 8 | printf("s.contains(\"foy\") => '%s'\n",s.contains("foy")?"true":"false"); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_ends_with.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | 5 | zetscript::String s="Hello World"; 6 | 7 | printf("s.endsWith(\"Hel\") => '%s \n" 8 | ,s.endsWith("Hel")?"true":"false"); 9 | 10 | printf("s.endsWith(\"orld\") => '%s' \n" 11 | ,s.endsWith("orld")?"true":"false"); 12 | 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_erase.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="Helilo World"; 5 | 6 | string.erase(3); 7 | printf("string.erase(3) => '%s'\n",string.toConstChar()); 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_find.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="the quick brown fox jumps over the lazy dog."; 5 | 6 | printf("string.find(\"the\") => %i\n",string.find("the")); 7 | printf("string.find(\"fox\") => %i\n",string.find("fox")); 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_find_last_of.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="the fox jumps over the lazy dog."; 5 | 6 | printf("string.findLastOf(\"the\") => %i\n",string.findLastOf("fo")); 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_get_substring.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="Hello World"; 5 | 6 | printf("string.substring(0) => '%s'\n",string.getSubstring(0).toConstChar()); 7 | printf("string.substring(3) => '%s'\n",string.getSubstring(3).toConstChar()); 8 | printf("string.substring(2,3) => '%s'\n",string.getSubstring(2,3).toConstChar()); 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_insert.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="Hello Wd"; 5 | 6 | string.insert(7,"orl"); 7 | printf("string.insert(7,\"orl\") => '%s'\n",string.toConstChar()); 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_is_empty.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | 5 | zetscript::String empty_string; 6 | zetscript::String non_empty_string="Hello World"; 7 | 8 | printf("empty_string.empty() => '%s' \n" 9 | ,empty_string.isEmpty()?"true":"false"); 10 | 11 | printf("non_empty_string.empty() => '%s' \n" 12 | ,non_empty_string.isEmpty()?"true":"false"); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_length.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::String string="Hello World"; 4 | 5 | printf("the length of '%s' is %i\n",string.toConstChar(),string.length()); 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_operator_access.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::String string="Hello World"; 4 | 5 | for(int c=0; c < string.length();c++){ 6 | printf("%c",string[c]); 7 | } 8 | 9 | printf("\n"); 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_operator_add.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string1="Hello",string2="World"; 5 | zetscript::String string=string1 + " "+ string2 + "!!"; 6 | 7 | printf("%s\n",string.toConstChar()); 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_operator_add_assign.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::String string; 4 | 5 | string="Hello"; 6 | string+=" World"; 7 | string+='!'; 8 | 9 | printf("%s",string.toConstChar()); 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_operator_assign.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | int main(){ 3 | zetscript::String string; 4 | 5 | string="Hello world"; 6 | 7 | printf("%s\n",string.toConstChar()); 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_relational_operators.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="Hello World"; 5 | zetscript::String string2="!!Hello World!!"; 6 | 7 | if(string == "Hello World"){ 8 | printf("string == 'Hello World'\n"); 9 | } 10 | 11 | if(string2 != "Hello World"){ 12 | printf("string2 != 'Hello World'\n"); 13 | } 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_replace.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String s="My blue car with blue door and blue wheel"; 5 | 6 | printf("s.replace(\"blue\",\"green\") => '%s'\n",s.replace("blue","green").toConstChar()); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_script_object_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::StringScriptObject *returnNewStringScriptObject( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | 7 | // instance new StringScriptObject using ScriptEngine instance 8 | zetscript::StringScriptObject *string_object=new zetscript::StringScriptObject(_script_engine,"Hello World!"); 9 | 10 | // ... 11 | 12 | return string_object; 13 | } 14 | 15 | int main(){ 16 | zetscript::ScriptEngine script_engine; 17 | 18 | // Registers returnNewStringScriptObject 19 | script_engine.registerFunction("returnNewStringScriptObject",returnNewStringScriptObject); 20 | 21 | // prints the returning of new string object 22 | script_engine.compileAndRun("Console::outln(returnNewStringScriptObject())"); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_script_object_get.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void printString( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::StringScriptObject *_string_object 6 | ){ 7 | printf("%s\n",_string_object->get().toConstChar()); 8 | } 9 | 10 | int main(){ 11 | zetscript::ScriptEngine script_engine; 12 | 13 | // registers printString 14 | script_engine.registerFunction("printString",printString); 15 | 16 | // calls printString 17 | script_engine.compileAndRun("printString(\"Hello World!\")"); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_script_object_get_const_char.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void printString( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::StringScriptObject *_string_object 6 | ){ 7 | printf("%s\n",_string_object->getConstChar()); 8 | } 9 | 10 | int main(){ 11 | zetscript::ScriptEngine script_engine; 12 | 13 | // registers printString 14 | script_engine.registerFunction("printString",printString); 15 | 16 | // calls printString 17 | script_engine.compileAndRun("printString(\"Hello World!\")"); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_script_object_length.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void printStringLength( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::StringScriptObject *_string_object 6 | ){ 7 | printf("The length of '%s' is %i\n",_string_object->toString().toConstChar(),_string_object->length()); 8 | } 9 | 10 | int main(){ 11 | zetscript::ScriptEngine script_engine; 12 | 13 | // registers printStringLength 14 | script_engine.registerFunction("printStringLength",printStringLength); 15 | 16 | // calls printStringLength 17 | script_engine.compileAndRun("printStringLength(\"Hello World!\")"); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_script_object_set.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | zetscript::StringScriptObject *returnString( 4 | zetscript::ScriptEngine *_script_engine 5 | ){ 6 | zetscript::StringScriptObject *string_object = new zetscript::StringScriptObject(_script_engine); 7 | string_object->set("Hello World!"); 8 | return string_object; 9 | } 10 | 11 | int main(){ 12 | zetscript::ScriptEngine script_engine; 13 | 14 | // registers returnString 15 | script_engine.registerFunction("returnString",returnString); 16 | 17 | // prints the value returned by returnString 18 | script_engine.compileAndRun("Console::outln(returnString())"); 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_script_object_to_string.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void printString( 4 | zetscript::ScriptEngine *_script_engine 5 | ,zetscript::StringScriptObject *_string_object 6 | ){ 7 | printf("%s\n",_string_object->toString().toConstChar()); 8 | } 9 | 10 | int main(){ 11 | zetscript::ScriptEngine script_engine; 12 | 13 | // registers printString 14 | script_engine.registerFunction("printString",printString); 15 | 16 | // calls printString 17 | script_engine.compileAndRun("printString(\"Hello World!\")"); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_set_substring.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="this is a test string."; 5 | zetscript::String str2="n example"; 6 | 7 | string.setSubstring(9,5,str2); 8 | 9 | printf("string.replace(9,5,str2) => '%s'\n",string.toConstChar()); 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_split.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String s="The quick brown fox jumps over the lazy dog."; 5 | 6 | zetscript::Vector v=s.split(' '); 7 | 8 | for(int i=0; i < v.length();i++ ){ 9 | printf("%s\n",v.get(i).toConstChar()); 10 | } 11 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_starts_with.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | 5 | zetscript::String s="Hello World"; 6 | 7 | printf("s.startsWith(\"Hel\") => '%s \n" 8 | ,s.startsWith("Hel")?"true":"false"); 9 | 10 | printf("s.startsWith(\"orld\") => '%s' \n" 11 | ,s.startsWith("orld")?"true":"false"); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_to_const_char.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String string="Hello World"; 5 | 6 | printf("string.toConstChar() => '%s'\n",string.toConstChar()); 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_to_lower_case.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String s="Hello World"; 5 | 6 | printf("s.toLowerCase() => '%s'",s.toLowerCase().toConstChar()); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /doc/examples/api/types/string_to_upper_case.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::String s="Hello World"; 5 | 6 | printf("s.toUpperCase() => '%s'",s.toUpperCase().toConstChar()); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_clear.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | for(int i=0; i < 10; i++){ 7 | vector.push(i); 8 | } 9 | 10 | vector.clear(); 11 | 12 | printf("vector.length() => %i\n",vector.length()); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_concat.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector1; 5 | zetscript::Vector vector2; 6 | zetscript::Vector vector3; 7 | 8 | for(int i=0; i < 2; i++){ 9 | vector1.push(i); 10 | } 11 | 12 | for(int i=2; i < 4; i++){ 13 | vector2.push(i); 14 | } 15 | vector3.concat(vector1); 16 | vector3.concat(vector2); 17 | 18 | printf("vector3 contents : ["); 19 | 20 | for(int i=0; i < vector3.length(); i++){ 21 | if(i>0){ 22 | printf(","); 23 | } 24 | printf("%i",vector3.get(i)); 25 | } 26 | 27 | printf("]\n"); 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_constructor.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | 5 | // empty vector of ints 6 | zetscript::Vector vector; 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_data.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | for(int i=0; i < 5; i++){ 7 | vector.push(i); 8 | } 9 | 10 | int *ptr_data=vector.data(); 11 | 12 | printf("contents from ptr_data : ["); 13 | 14 | for(int i=0; i < vector.length(); i++){ 15 | if(i>0){ 16 | printf(","); 17 | } 18 | printf("%i",*ptr_data++); 19 | } 20 | 21 | printf("]\n"); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_erase.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | for(int i=0; i < 5; i++){ 7 | vector.push(i); 8 | } 9 | 10 | vector.erase(2); 11 | 12 | printf("vector contents : ["); 13 | for(int i=0; i < vector.length(); i++){ 14 | if(i>0){ 15 | printf(","); 16 | } 17 | printf("%i",vector.get(i)); 18 | } 19 | 20 | printf("]\n"); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_get.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | vector.push(10); 7 | vector.push(100); 8 | vector.push(1000); 9 | 10 | printf("vector.get(1) => %i\n",vector.get(1)); 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_insert.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | vector.push(1); 7 | vector.push(2); 8 | vector.push(4); 9 | 10 | // insert integer 3 at position 2 11 | vector.insert(2,3); 12 | 13 | printf("vector contents : ["); 14 | 15 | for(int i=0; i < vector.length(); i++){ 16 | if(i>0){ 17 | printf(","); 18 | } 19 | printf("%i",vector.get(i)); 20 | } 21 | 22 | printf("]\n"); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_length.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | vector.push(1); 7 | vector.push(2); 8 | vector.push(3); 9 | 10 | printf("vector.length() => %i",vector.length()); 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_operator_assign.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector1,vector2; 5 | 6 | vector1.push(1); 7 | vector1.push(2); 8 | vector1.push(3); 9 | vector1.push(4); 10 | 11 | vector2=vector1; 12 | 13 | printf("vector2 contents : ["); 14 | 15 | for(int i=0; i < vector2.length(); i++){ 16 | if(i>0){ 17 | printf(","); 18 | } 19 | printf("%i",vector2.get(i)); 20 | } 21 | 22 | printf("]\n"); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_pop.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | vector.push(1); 7 | vector.push(2); 8 | vector.push(3); 9 | vector.push(4); 10 | 11 | vector.pop(); 12 | 13 | printf("vector contents : ["); 14 | 15 | for(int i=0; i < vector.length(); i++){ 16 | if(i>0){ 17 | printf(","); 18 | } 19 | printf("%i",vector.get(i)); 20 | } 21 | 22 | printf("]\n"); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_push.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | vector.push(1); 7 | vector.push(2); 8 | vector.push(3); 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_resize.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | vector.resize(4); 7 | 8 | for(int i=0; i < vector.length(); i++){ 9 | vector.set(i,i); 10 | } 11 | 12 | printf("vector contents : ["); 13 | 14 | for(int i=0; i < vector.length(); i++){ 15 | if(i>0){ 16 | printf(","); 17 | } 18 | printf("%i",vector.get(i)); 19 | } 20 | 21 | printf("]\n"); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /doc/examples/api/types/vector_set.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | int main(){ 4 | zetscript::Vector vector; 5 | 6 | vector.push(1); 7 | vector.push(100); 8 | vector.push(3); 9 | 10 | vector.set(1,2); // vector = [1,2,3] 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /doc/examples/language/array/array_clear.zs: -------------------------------------------------------------------------------- 1 | var v=[0,1,2,3] 2 | Console::outln("v => {0}",v) 3 | v.clear() 4 | Console::outln("v => {0}",v) -------------------------------------------------------------------------------- /doc/examples/language/array/array_concat.zs: -------------------------------------------------------------------------------- 1 | var v=[0,1,2,3] 2 | Console::outln("v => {0}",v) 3 | Console::outln("Array::concat(v,[4,5,6,7]) => {0}",Array::concat(v,[4,5,6,7])) -------------------------------------------------------------------------------- /doc/examples/language/array/array_contains.zs: -------------------------------------------------------------------------------- 1 | var v=[1,"string",false,10.5] 2 | Console::outln("v => {0}",v) 3 | Console::outln("v.contains(\"string\") => {0}",v.contains("string")) 4 | Console::outln("v.contains(10) => {0}",v.contains(10)) 5 | Console::outln("v.contains(10.5) => {0}",v.contains(10.5)) 6 | -------------------------------------------------------------------------------- /doc/examples/language/array/array_erase_at.zs: -------------------------------------------------------------------------------- 1 | var v=[0,1,2,3] 2 | Console::outln("v => {0}",v) 3 | v.eraseAt(1) 4 | Console::outln("v.eraseAt(1) => {0}",v) -------------------------------------------------------------------------------- /doc/examples/language/array/array_extend.zs: -------------------------------------------------------------------------------- 1 | var v=[0,1,2,3] 2 | Console::outln("v => {0}",v) 3 | v.extend([4,5,6,7]) 4 | Console::outln("v.extend([4,5,6,7]) => {0}",v) -------------------------------------------------------------------------------- /doc/examples/language/array/array_insert_at.zs: -------------------------------------------------------------------------------- 1 | var v=[0,2,3] 2 | Console::outln("v => {0}",v) 3 | v.insertAt(1,1) 4 | Console::outln("v.eraseAt(1) => {0}",v) -------------------------------------------------------------------------------- /doc/examples/language/array/array_join.zs: -------------------------------------------------------------------------------- 1 | var v=["The","quick","brown","fox","jumps","over","the","lazy","dog."]; 2 | Console::outln("v => '{0}'",v) 3 | Console::outln("v.join(' ') => {0}",v.join(' ')) 4 | -------------------------------------------------------------------------------- /doc/examples/language/array/array_length.zs: -------------------------------------------------------------------------------- 1 | Console::outln([1,"string",true,2.0].length) -------------------------------------------------------------------------------- /doc/examples/language/array/array_pop.zs: -------------------------------------------------------------------------------- 1 | var v=[0,1,2,3,4] 2 | Console::outln("v => {0}",v) 3 | var r=v.pop() 4 | Console::outln("v.pop() => v:{0} r:{1}",v,r) 5 | -------------------------------------------------------------------------------- /doc/examples/language/array/array_push.zs: -------------------------------------------------------------------------------- 1 | var v=[0,1,2,3] 2 | Console::outln("v => {0}",v) 3 | v.push(4) 4 | Console::outln("v.push(4) => {0}",v) -------------------------------------------------------------------------------- /doc/examples/language/class/class_extension.zs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jespa007/zetscript/d73cbd8bc85437a5a776e8b6e0bba447749fc1b7/doc/examples/language/class/class_extension.zs -------------------------------------------------------------------------------- /doc/examples/language/class/class_inicialization_member_methods.zs: -------------------------------------------------------------------------------- 1 | class Test{ 2 | 3 | constructor(){ 4 | Console::outln("call from constructor()") 5 | this.member1(); 6 | } 7 | 8 | member1(){ 9 | Console::outln("call from member1()") 10 | } 11 | 12 | member2(){ 13 | Console::outln("call from member2()") 14 | } 15 | } 16 | 17 | var test=new Test(); 18 | 19 | test.member2(); -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_addassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _addassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ += _op1; 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ += _op1.__value__; 11 | }else{ 12 | System::error("Number::_addassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(20); 21 | Console::outln("number+=20 => {0}",number+=20) 22 | Console::outln("number+=new Number(30) => {0}",number+=new Number(30)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_andassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _andassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ &= Integer::parse(_op1); 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ &= Integer::parse(_op1.__value__); 11 | }else{ 12 | System::error("Number::_andassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(0xff); 21 | Console::outln("number&=0x3 => {0}",number&=0x3) 22 | Console::outln("number&=new Number(0x1) => {0}",number&=new Number(0x1)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_bwc.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _bwc(){ 7 | return ~Integer::parse(this.__value__); 8 | } 9 | 10 | }; 11 | 12 | var number=new Number(2) 13 | 14 | Console::outln("~number => "+ (~number)) 15 | 16 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_divassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _divassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ /= _op1; 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ /= _op1.__value__; 11 | }else{ 12 | System::error("Number::_divassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(20); 21 | Console::outln("number/=20 => {0}",number/=20) 22 | Console::outln("number/=new Number(30) => {0}",number/=new Number(30)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_gt.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | static _gt(_op1, _op2){ 7 | var op1,op2 8 | if(_op1 instanceof Integer || _op1 instanceof Float){ 9 | op1 = _op1; 10 | }else if(_op1 instanceof Number){ 11 | op1 = _op1.__value__; 12 | }else{ 13 | System::error("Number::_gt : right operand not supported"); 14 | } 15 | 16 | if(_op2 instanceof Integer || _op2 instanceof Float){ 17 | op2 = _op2; 18 | }else if(_op2 instanceof Number){ 19 | op2 = _op2.__value__; 20 | }else{ 21 | System::error("Number::_gt : left operand not supported"); 22 | } 23 | return op1>op2; 24 | } 25 | }; 26 | 27 | Console::outln("new Number(20) > 20 => "+(new Number(20) > 20)) 28 | Console::outln("20 > new Number(30) => "+(20 > new Number(30))) 29 | Console::outln("new Number(30) > new Number(20) => "+(new Number(30) > new Number(20))) -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_in.zs: -------------------------------------------------------------------------------- 1 | class Data{ 2 | constructor(){ 3 | this.data=[0,1,1,10,3,4,6] 4 | } 5 | 6 | _in(_value){ 7 | return _value in this.data; 8 | } 9 | }; 10 | 11 | var data=new Data(); 12 | 13 | if(10 in data){ 14 | Console::outln("10 is content in data") 15 | } 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_iterator.zs: -------------------------------------------------------------------------------- 1 | class ContainerIterator{ 2 | constructor(_container){ 3 | this.container=_container; 4 | this.index=0; 5 | } 6 | _get(){ 7 | // returns 2 values: index as key and this.container.data[this.index] as value 8 | return this.index,this.container.data[this.index]; 9 | } 10 | _next(){ 11 | if(this._end()){ 12 | return; 13 | } 14 | this.index++; 15 | 16 | } 17 | _end(){ 18 | return this.index>=this.container.data.length; 19 | } 20 | } 21 | 22 | class Container{ 23 | constructor(){ 24 | this.data=[10,20,30,40,50,60,70] 25 | } 26 | 27 | _iter(){ 28 | return new ContainerIterator(this) 29 | } 30 | } 31 | 32 | var container=new Container(); 33 | 34 | 35 | // iterate over all elements 36 | for(var k,v in container){ 37 | Console::outln("key: {0} value: {1}",k,v) 38 | } -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_lt.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | static _lt(_op1, _op2){ 7 | var op1,op2 8 | if(_op1 instanceof Integer || _op1 instanceof Float){ 9 | op1 = _op1; 10 | }else if(_op1 instanceof Number){ 11 | op1 = _op1.__value__; 12 | }else{ 13 | System::error("Number::_lt : right operand not supported"); 14 | } 15 | 16 | if(_op2 instanceof Integer || _op2 instanceof Float){ 17 | op2 = _op2; 18 | }else if(_op2 instanceof Number){ 19 | op2 = _op2.__value__; 20 | }else{ 21 | System::error("Number::_lt : left operand not supported"); 22 | } 23 | return op1 "+(new Number(20) < 20)) 28 | Console::outln("20 < new Number(30) => "+(20 < new Number(30))) 29 | Console::outln("new Number(30) < new Number(20) => "+(new Number(30) < new Number(20))) -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_modassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _modassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ %= _op1; 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ %= _op1.__value__; 11 | }else{ 12 | System::error("Number::_modassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(250); 21 | Console::outln("number%=30 => {0}",number%=30) 22 | Console::outln("number%=new Number(100) => {0}",number%=new Number(100)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_mulassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _mulassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ *= _op1; 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ *= _op1.__value__; 11 | }else{ 12 | System::error("Number::_mulassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(20); 21 | Console::outln("number*=20 => {0}",number*=20) 22 | Console::outln("number*=new Number(30) => {0}",number*=new Number(30)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_neg.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _neg(){ 7 | return -this.__value__; 8 | } 9 | 10 | }; 11 | 12 | var number=new Number(20) 13 | 14 | Console::outln("-number => "+ (-number)) 15 | 16 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_not.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _not(){ 7 | return this.__value__==0 || this.__value__==undefined || this.__value__ == null; 8 | } 9 | 10 | }; 11 | 12 | var number=new Number() 13 | 14 | if(!number){ 15 | Console::outln("Number is empty") 16 | } -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_orassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _orassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ |= Integer::parse(_op1); 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ |= Integer::parse(_op1.__value__); 11 | }else{ 12 | System::error("Number::_orassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(0x1); 21 | Console::outln("number|=0x2 => {0}",number|=0x2) 22 | Console::outln("number|=new Number(0x4) => {0}",number|=new Number(0x4)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_postdec.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _postdec(){ 7 | return new Number(this.__value__--); 8 | } 9 | 10 | _tostring(){ 11 | return this.__value__; 12 | } 13 | } 14 | 15 | var number=new Number(20); 16 | Console::outln("number-- => "+(number--)) 17 | Console::outln("number => "+(number)) 18 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_postinc.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _postinc(){ 7 | return new Number(this.__value__++); 8 | } 9 | 10 | _tostring(){ 11 | return this.__value__; 12 | } 13 | } 14 | 15 | var number=new Number(20); 16 | Console::outln("number++ => "+(number++)) 17 | Console::outln("number => "+(number)) 18 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_predec.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _predec(){ 7 | return new Number(--this.__value__); 8 | } 9 | 10 | _tostring(){ 11 | return this.__value__; 12 | } 13 | } 14 | 15 | var number=new Number(20); 16 | Console::outln("--number => "+(--number)) 17 | Console::outln("number => "+(number)) 18 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_preinc.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _preinc(){ 7 | return new Number(++this.__value__); 8 | } 9 | 10 | _tostring(){ 11 | return this.__value__; 12 | } 13 | } 14 | 15 | var number=new Number(20); 16 | Console::outln("++number => "+(++number)) 17 | Console::outln("number => "+(number)) 18 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_set.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | _set(_value){ 6 | if(_value instanceof Integer || _value instanceof Float){ 7 | this.__value__ = _value; 8 | }else if(_value instanceof Number){ 9 | this.__value__ = _value.__value__; 10 | }else{ 11 | System::error("Number::set : parameter not supported"); 12 | } 13 | } 14 | _tostring(){ 15 | return this.__value__; 16 | } 17 | }; 18 | 19 | var n=new Number (); 20 | Console::outln("n => "+n) 21 | 22 | n=10; 23 | Console::outln("n=10 => "+n) 24 | 25 | n=new Number(20); 26 | Console::outln("n=new Number(20) => "+n) 27 | 28 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_shlassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _shlassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ <<= Integer::parse(_op1); 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ <<= Integer::parse(_op1.__value__); 11 | }else{ 12 | System::error("Number::_shlassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(0x1); 21 | Console::outln("number<<=1 => {0}",number<<=1) 22 | Console::outln("number<<=new Number(1) => {0}",number<<=new Number(1)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_shrassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _shrassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ >>= Integer::parse(_op1); 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ >>= Integer::parse(_op1.__value__); 11 | }else{ 12 | System::error("Number::_shrassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(0x10); 21 | Console::outln("number>>=1 => {0}",number>>=1) 22 | Console::outln("number>>=new Number(1) => {0}",number>>=new Number(1)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_subassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _subassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ -= _op1; 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ -= _op1.__value__; 11 | }else{ 12 | System::error("Number::_subassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(20); 21 | Console::outln("number-=20 => {0}",number-=20) 22 | Console::outln("number-=new Number(30) => {0}",number-=new Number(30)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_tostring.zs: -------------------------------------------------------------------------------- 1 | class NumberWithoutString{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | }; 6 | 7 | class Number{ 8 | constructor(_value=0){ 9 | this.__value__=_value; 10 | } 11 | 12 | _tostring(){ 13 | return this.__value__; // returns this.__value__ when string operation is involved 14 | } 15 | }; 16 | 17 | Console::outln("without _tostring => "+new NumberWithoutString(10)) 18 | Console::outln("with _tostring => "+new Number(10)) -------------------------------------------------------------------------------- /doc/examples/language/class/class_metamethod_xorassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | _xorassign(_op1){ 7 | if(_op1 instanceof Integer || _op1 instanceof Float){ 8 | this.__value__ ^= Integer::parse(_op1); 9 | }else if(_op1 instanceof Number){ 10 | this.__value__ ^= Integer::parse(_op1.__value__); 11 | }else{ 12 | System::error("Number::_xorassign : right operand not supported"); 13 | } 14 | } 15 | _tostring(){ 16 | return this.__value__; 17 | } 18 | }; 19 | 20 | var number=new Number(0); 21 | Console::outln("number^=0xa => {0}",number^=0xa) 22 | Console::outln("number^=new Number(0x9) => {0}",number^=new Number(0x9)) 23 | 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_addassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _addassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ += _op1; 15 | }else{ 16 | System::error("Number::value::_addassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(20); 23 | Console::outln("number.value+=20 => {0}",number.value+=20) 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_andassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _andassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ &= Integer::parse(_op1); 15 | }else{ 16 | System::error("Number::value::_andassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(0xf); 23 | Console::outln("number.value&=0x3 => {0}",number.value&=0x3) 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_divassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _divassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ /= _op1; 15 | }else{ 16 | System::error("Number::value::_divassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(10); 23 | Console::outln("number.value/=20 => {0}",number.value/=20) 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_get.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | } 12 | } 13 | 14 | var number=new Number(20); 15 | Console::outln("number.value => "+number.value) 16 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_modassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _modassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ %= _op1; 15 | }else{ 16 | System::error("Number::value::_modassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(250); 23 | Console::outln("number.value%=100 => {0}",number.value%=100) -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_mulassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _mulassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ *= _op1; 15 | }else{ 16 | System::error("Number::value::_mulassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(10); 23 | Console::outln("number.value*=10 => {0}",number.value*=10) 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_orassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _orassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ |= Integer::parse(_op1); 15 | }else{ 16 | System::error("Number::value::_orassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(0x1); 23 | Console::outln("number.value|=0x2 => {0}",number.value|=0x2) 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_postdec.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _postdec(){ 13 | return this.__value__--; 14 | } 15 | } 16 | } 17 | 18 | var number=new Number(20); 19 | Console::outln("number.value-- => {0}",number.value--) 20 | Console::outln("number.value => {0}",number.value) 21 | 22 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_postinc.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | 7 | // property 'value' 8 | value{ 9 | _get(){ 10 | return this.__value__ 11 | } 12 | 13 | _postinc(){ 14 | return this.__value__++; 15 | } 16 | } 17 | } 18 | 19 | var number=new Number(20); 20 | Console::outln("number.value++ => {0}",number.value++) 21 | Console::outln("number.value => {0}",number.value) 22 | 23 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_predec.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _predec(){ 13 | return --this.__value__; 14 | } 15 | } 16 | } 17 | 18 | var number=new Number(20); 19 | Console::outln("--number.value => {0}",--number.value) 20 | Console::outln("number.value => {0}",number.value) 21 | 22 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_preinc.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | 7 | // property 'value' 8 | value{ 9 | _get(){ 10 | return this.__value__ 11 | } 12 | 13 | _preinc(){ 14 | return ++this.__value__; 15 | } 16 | } 17 | } 18 | 19 | var number=new Number(20); 20 | Console::outln("++number.value => {0}",++number.value) 21 | Console::outln("number.value => {0}",number.value) 22 | 23 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_set.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.value=_value // calls Number::value::_set metamethod 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _set(_value){ 13 | if(_value instanceof Integer || _value instanceof Float){ 14 | this.__value__ = _value; 15 | }else if(_value instanceof Number){ 16 | this.__value__ = _value.__value__; 17 | }else{ 18 | System::error("Number::value::_set : parameter not supported"); 19 | } 20 | } 21 | } 22 | } 23 | 24 | var number=new Number(20); 25 | Console::outln("On operation 'number=new Number(20)' then 'number.value' is => "+number.value) 26 | 27 | number.value = 10; 28 | Console::outln("On operation 'number=10' the 'number.value' is => "+number.value) 29 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_shlassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _shlassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ <<= Integer::parse(_op1); 15 | }else{ 16 | System::error("Number::value::_shlassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(0x1); 23 | Console::outln("number.value<<=1 => {0}",number.value<<=1) 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_shrassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _shrassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ >>= Integer::parse(_op1); 15 | }else{ 16 | System::error("Number::value::_shrassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number = new Number(0x8); 23 | Console::outln("number.value>>=1 => {0}",number.value>>=1) -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_subassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _subassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ -= _op1; 15 | }else{ 16 | System::error("Number::value::_subassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(30); 23 | Console::outln("number.value-=20 => {0}",number.value-=20) 24 | -------------------------------------------------------------------------------- /doc/examples/language/class/class_property_metamethod_xorassign.zs: -------------------------------------------------------------------------------- 1 | class Number{ 2 | constructor(_value=0){ 3 | this.__value__=_value; 4 | } 5 | 6 | // property 'value' 7 | value{ 8 | _get(){ 9 | return this.__value__ 10 | } 11 | 12 | _xorassign(_op1){ 13 | if(_op1 instanceof Integer || _op1 instanceof Float){ 14 | this.__value__ ^= Integer::parse(_op1); 15 | }else{ 16 | System::error("Number::value::_xorassign : right operand not supported"); 17 | } 18 | } 19 | } 20 | } 21 | 22 | var number=new Number(0x0); 23 | Console::outln("number.value^=0xa => {0}",number.value^=0xa) 24 | -------------------------------------------------------------------------------- /doc/examples/language/console/console_error.zs: -------------------------------------------------------------------------------- 1 | Console::error("An") 2 | Console::error(" ") 3 | Console::error(" error happened!") 4 | -------------------------------------------------------------------------------- /doc/examples/language/console/console_errorln.zs: -------------------------------------------------------------------------------- 1 | Console::error("Print error 1") 2 | Console::error("Print error 2") -------------------------------------------------------------------------------- /doc/examples/language/console/console_out.zs: -------------------------------------------------------------------------------- 1 | Console::out("Hello") 2 | Console::out(" ") 3 | Console::out("World") -------------------------------------------------------------------------------- /doc/examples/language/console/console_outln.zs: -------------------------------------------------------------------------------- 1 | Console::outln("Hello") 2 | Console::outln() 3 | Console::outln("World") -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_add_days.zs: -------------------------------------------------------------------------------- 1 | var now = DateTime::now(); 2 | Console::outln("now => {0}", now); 3 | now.addDays(36); 4 | Console::outln("after +36 days from now => {0}", now); -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_add_hours.zs: -------------------------------------------------------------------------------- 1 | var now = DateTime::now(); 2 | Console::outln("now => {0}", now); 3 | now.addHours(4); 4 | Console::outln("after +4 hours from now => {0}", now); -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_add_minutes.zs: -------------------------------------------------------------------------------- 1 | var now = DateTime::now(); 2 | Console::outln("now => {0}", now); 3 | now.addMinutes(10); 4 | Console::outln("after +10 minutes from now => {0}", now); -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_add_months.zs: -------------------------------------------------------------------------------- 1 | var now = DateTime::now(); 2 | Console::outln("now => {0}", now); 3 | now.addMonths(10); 4 | Console::outln("after +10 months from now => {0}", now); -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_add_seconds.zs: -------------------------------------------------------------------------------- 1 | var now = DateTime::now(); 2 | Console::outln("now => {0}", now); 3 | now.addSeconds(10); 4 | Console::outln("after +10 seconds from now => {0}", now); -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_add_years.zs: -------------------------------------------------------------------------------- 1 | var now = DateTime::now(); 2 | Console::outln("now => {0}", now); 3 | now.addYears(3); 4 | Console::outln("after +3 years from now => {0}", now); -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_constructor.zs: -------------------------------------------------------------------------------- 1 | Console::outln(new DateTime(1979,9,6,12,00,00)) -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_member_properties.zs: -------------------------------------------------------------------------------- 1 | var now = DateTime::now(); 2 | Console::outln("now => "+ now); 3 | Console::outln("now.week_day => "+ now.week_day); 4 | Console::outln("now.month_day => "+ now.month_day); 5 | Console::outln("now.year_day => "+ now.year_day); 6 | Console::outln("now.second => "+ now.second); 7 | Console::outln("now.minute => "+ now.minute); 8 | Console::outln("now.hour => "+ now.hour); 9 | Console::outln("now.day => "+ now.day); 10 | Console::outln("now.month => "+ now.month); 11 | Console::outln("now.year => "+ now.year); 12 | -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_metamethod_sub.zs: -------------------------------------------------------------------------------- 1 | var birth=new DateTime(1979,9,6,12,00,00) 2 | Console::outln("birth => "+birth) 3 | var now=DateTime::now() 4 | var diff=now-birth; 5 | Console::outln("years => "+Integer::parse(diff.days/365)) -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_now.zs: -------------------------------------------------------------------------------- 1 | Console::outln("DateTime::now() => " + DateTime::now()) -------------------------------------------------------------------------------- /doc/examples/language/datetime/datetime_now_utc.zs: -------------------------------------------------------------------------------- 1 | Console::outln("DateTime::now() => " + DateTime::now()) 2 | Console::outln("DateTime::nowUtc() => "+DateTime::nowUtc()) -------------------------------------------------------------------------------- /doc/examples/language/float/float_parse.zs: -------------------------------------------------------------------------------- 1 | Console::outln(Float::parse("10.5")) 2 | Console::outln(Float::parse(15)) 3 | -------------------------------------------------------------------------------- /doc/examples/language/function/function_parameter_by_reference.zs: -------------------------------------------------------------------------------- 1 | function swap(ref _a, ref _b){ 2 | var tmp=_a 3 | _a=_b; 4 | _b=tmp; 5 | } 6 | 7 | var i=5,j=10; 8 | 9 | Console::outln("i:{0} j:{1}",i,j) 10 | 11 | swap(i,j) 12 | 13 | Console::outln("swap(i,j) => i:{0} j:{1}",i,j) 14 | 15 | -------------------------------------------------------------------------------- /doc/examples/language/function/function_rest_parameters.zs: -------------------------------------------------------------------------------- 1 | function number(str,...args) { 2 | var number = 0; 3 | for (var arg in args) { 4 | number += arg; 5 | } 6 | return str+number; 7 | } 8 | 9 | var res=number("Total number is = ",1, 10, 100, 1000, 10000); 10 | 11 | Console::outln(res) -------------------------------------------------------------------------------- /doc/examples/language/integer/integer_parse.zs: -------------------------------------------------------------------------------- 1 | Console::outln(Integer::parse("10")) 2 | Console::outln(Integer::parse(15.5)) 3 | -------------------------------------------------------------------------------- /doc/examples/language/json/json_deserialize.zs: -------------------------------------------------------------------------------- 1 | var json_string="{\n"+ 2 | "\"encoding\" : \"UTF-8\",\n"+ 3 | "\"number\": 3.34E-5\n"+ 4 | ",\"plug_ins\" : [\n"+ 5 | "\"python\",\n"+ 6 | "\"c++\",\n"+ 7 | "\"ruby\"\n"+ 8 | "]\n"+ 9 | ",\"indent\" : { \"length\" : 3, \"use_space\": true }\n"+ 10 | "}" 11 | 12 | var deseriazed_json_string=Json::deserialize(json_string); 13 | Console::outln("Deserialized json result:\n") 14 | for(var k,v in deseriazed_json_string){ 15 | Console::outln("key => '{0}' value => {1} ",k,v) 16 | } 17 | -------------------------------------------------------------------------------- /doc/examples/language/json/json_serialize.zs: -------------------------------------------------------------------------------- 1 | var object={ 2 | encoding : "UTF-8" 3 | ,number: 3.34E-5 4 | ,plug_ins : [ 5 | "python", 6 | "c++", 7 | "ruby" 8 | ] 9 | ,indent : { "length" : 3, "use_space": true } 10 | } 11 | 12 | Console::outln("serialize :") 13 | Console::outln() 14 | Console::outln(Json::serialize(object)) 15 | Console::outln() 16 | Console::outln("serialize with format : ") 17 | Console::outln() 18 | Console::outln(Json::serialize(object,true)) -------------------------------------------------------------------------------- /doc/examples/language/loop/loop_break.zs: -------------------------------------------------------------------------------- 1 | for(var i=0; i < 10; i++){ 2 | 3 | // At i==4 breaks iteration 4 | if(i==4){ 5 | break; 6 | } 7 | Console::outln(i); 8 | } -------------------------------------------------------------------------------- /doc/examples/language/loop/loop_continue.zs: -------------------------------------------------------------------------------- 1 | for(var i=0; i < 10; i++){ 2 | if(i%2==1){ 3 | continue; 4 | } 5 | 6 | // Only iterates within pair numbers 7 | Console::outln(i); 8 | } -------------------------------------------------------------------------------- /doc/examples/language/loop/loop_do_while.zs: -------------------------------------------------------------------------------- 1 | var i=0; 2 | 3 | do{ 4 | Console::outln(i); 5 | i++; 6 | }while(i < 5); -------------------------------------------------------------------------------- /doc/examples/language/loop/loop_for.zs: -------------------------------------------------------------------------------- 1 | for(var i=0; i < 5; i++){ 2 | Console::outln(i); 3 | } -------------------------------------------------------------------------------- /doc/examples/language/loop/loop_for_in.zs: -------------------------------------------------------------------------------- 1 | var object={a:10,b:10.5,c:"string",d:true} 2 | 3 | Console::outln("Iterate object and get value\n") 4 | 5 | for(var v in object){ 6 | Console::outln("v => "+v); 7 | } 8 | 9 | Console::outln("\nIterate object and get pair key-value\n") 10 | 11 | for(var k,v in object){ 12 | Console::outln("k => "+k+" v => "+v); 13 | } 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/language/loop/loop_while.zs: -------------------------------------------------------------------------------- 1 | var i=0; 2 | 3 | while(i < 5){ 4 | Console::outln(i); 5 | i++; 6 | } -------------------------------------------------------------------------------- /doc/examples/language/math/math_abs.zs: -------------------------------------------------------------------------------- 1 | Console::outln("The absolute value of 3.1416 is " + Math::abs(3.1416) ); 2 | Console::outln("The absolute value of -10.6 is " + Math::abs(-10.6) ); -------------------------------------------------------------------------------- /doc/examples/language/math/math_ceil.zs: -------------------------------------------------------------------------------- 1 | Console::outln( "ceil of 2.3 is "+Math::ceil(2.3) ); 2 | Console::outln( "ceil of 3.8 is "+Math::ceil(3.8) ); 3 | Console::outln( "ceil of -2.3 is "+Math::ceil(-2.3) ); 4 | Console::outln( "ceil of -3.8 is "+Math::ceil(-3.8) ); -------------------------------------------------------------------------------- /doc/examples/language/math/math_cos.zs: -------------------------------------------------------------------------------- 1 | Console::outln("The cosine of 60 degrees is "+Math::cos(Math::degToRad(60))) 2 | -------------------------------------------------------------------------------- /doc/examples/language/math/math_deg_to_rad.zs: -------------------------------------------------------------------------------- 1 | Console::outln("Math::degToRad(30) => "+Math::degToRad(30)) 2 | -------------------------------------------------------------------------------- /doc/examples/language/math/math_floor.zs: -------------------------------------------------------------------------------- 1 | Console::outln( "floor of 2.3 is "+Math::floor(2.3) ); 2 | Console::outln( "floor of 3.8 is "+Math::floor(3.8) ); 3 | Console::outln( "floor of -2.3 is "+Math::floor(-2.3) ); 4 | Console::outln( "floor of -3.8 is "+Math::floor(-3.8) ); -------------------------------------------------------------------------------- /doc/examples/language/math/math_max.zs: -------------------------------------------------------------------------------- 1 | Console::outln("The maximum of 20 and 30 is : "+Math::max(20,30)) -------------------------------------------------------------------------------- /doc/examples/language/math/math_min.zs: -------------------------------------------------------------------------------- 1 | Console::outln("The minimum of 20 and 30 is : "+Math::min(20,30)) -------------------------------------------------------------------------------- /doc/examples/language/math/math_pi.zs: -------------------------------------------------------------------------------- 1 | Console::outln(Math::PI) -------------------------------------------------------------------------------- /doc/examples/language/math/math_pow.zs: -------------------------------------------------------------------------------- 1 | Console::outln("7 ^ 3 = " + Math::pow (7.0, 3.0) ); 2 | Console::outln("4.73 ^ 12 = "+ Math::pow (4.73, 12.0) ); 3 | Console::outln("32.01 ^ 1.54 = "+ Math::pow (32.01, 1.54) ); -------------------------------------------------------------------------------- /doc/examples/language/math/math_random.zs: -------------------------------------------------------------------------------- 1 | for(var i=0; i < 5; i++){ 2 | Console::outln("random value : "+Math::random()); 3 | } -------------------------------------------------------------------------------- /doc/examples/language/math/math_round.zs: -------------------------------------------------------------------------------- 1 | Console::outln("round of 2.3 is " + Math::round(2.3) ); 2 | Console::outln("round of 3.8 is " + Math::round(3.8) ); 3 | Console::outln("round of 5.5 is " + Math::round(5.5) ); 4 | Console::outln("round of -2.3 is "+ Math::round(-2.3) ); 5 | Console::outln("round of -3.8 is "+ Math::round(-3.8) ); 6 | Console::outln("round of -5.5 is "+ Math::round(-5.5) ); -------------------------------------------------------------------------------- /doc/examples/language/math/math_sin.zs: -------------------------------------------------------------------------------- 1 | Console::outln("The sine of 30 degrees is "+Math::sin(Math::degToRad(30))) 2 | -------------------------------------------------------------------------------- /doc/examples/language/math/math_sqrt.zs: -------------------------------------------------------------------------------- 1 | Console::outln ("Math::sqrt(1024.0) = "+ Math::sqrt(1024.0)); -------------------------------------------------------------------------------- /doc/examples/language/object/object_clear.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:2,c:3,d:4}; 2 | 3 | Console::outln("o => {0}",o) 4 | Object::clear(o) 5 | Console::outln("Object::clear(o) => {0}",o) 6 | -------------------------------------------------------------------------------- /doc/examples/language/object/object_concat.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:2,c:3,d:4}; 2 | var e={e:5,f:6} 3 | 4 | Console::outln("o => {0}",o) 5 | Console::outln("e => {0}",e) 6 | Console::outln("Object::Concat(o,e) => {0}",Object::concat(o,e)) 7 | -------------------------------------------------------------------------------- /doc/examples/language/object/object_contains.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:"string",c:false,d:10.5} 2 | 3 | Console::outln("o => {0}",o) 4 | Console::outln("Object::contains(o,\"b\") => {0}",Object::contains(o,"b")) 5 | Console::outln("Object::contains(o,\"string\") => {0}",Object::contains(o,"string")) 6 | 7 | -------------------------------------------------------------------------------- /doc/examples/language/object/object_erase.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:2,c:3,d:4}; 2 | 3 | Console::outln("o => {0}",o) 4 | Object::erase(o,"b"); 5 | Console::outln("Object::erase(o,\"b\") => {0}",o) -------------------------------------------------------------------------------- /doc/examples/language/object/object_extend.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:2,c:3,d:4}; 2 | var e={e:5,f:6} 3 | 4 | Console::outln("o => {0}",o) 5 | Console::outln("e => {0}",e) 6 | Object::extend(o,e) 7 | Console::outln("Object::extend(o,e) => {0}",o) 8 | 9 | 10 | -------------------------------------------------------------------------------- /doc/examples/language/object/object_keys.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:2,c:3,d:4}; 2 | 3 | Console::outln("o => {0}",o) 4 | Console::outln("Object::keys(o) => {0}",Object::keys(o)) 5 | -------------------------------------------------------------------------------- /doc/examples/language/string/string_append.zs: -------------------------------------------------------------------------------- 1 | var s="Hell" 2 | Console::outln("s => '{0}'",s); 3 | s.append('o') 4 | Console::outln("s.append('o') => '{0}'",s); 5 | s.append(" World") 6 | Console::outln("s.append(\" World\") => '{0}'",s); 7 | -------------------------------------------------------------------------------- /doc/examples/language/string/string_clear.zs: -------------------------------------------------------------------------------- 1 | var s="Hello World" 2 | Console::outln("s => '{0}'",s) 3 | s.clear() 4 | Console::outln("s.clear() => '{0}'",s) -------------------------------------------------------------------------------- /doc/examples/language/string/string_contains.zs: -------------------------------------------------------------------------------- 1 | var s="The quick brown fox jumps over the lazy dog."; 2 | Console::outln("s => '{0}'",s) 3 | Console::outln("s.contains(\"fo\") => {0}",s.contains("fo")) 4 | Console::outln("s.contains(\"foy\") => {0}",s.contains("foy")) -------------------------------------------------------------------------------- /doc/examples/language/string/string_ends_with.zs: -------------------------------------------------------------------------------- 1 | var s = "Hello"; 2 | Console::outln("s.endsWith(\"Hel\") => '{0}'", s.endsWith("Hel")); 3 | Console::outln("s.endsWith(\"llo\") => '{0}'",s.endsWith("llo")); 4 | Console::outln("s.endsWith(\"o\") => '{0}'",s.endsWith("o")); -------------------------------------------------------------------------------- /doc/examples/language/string/string_erase_at.zs: -------------------------------------------------------------------------------- 1 | var s="helilo world"; 2 | 3 | Console::outln("s => '{0}'",s); 4 | s.eraseAt(3); 5 | Console::outln("s.eraseAt(3) => '{0}'",s) 6 | -------------------------------------------------------------------------------- /doc/examples/language/string/string_format.zs: -------------------------------------------------------------------------------- 1 | Console::outln(String::format("Format first arg => {0}",1)) 2 | Console::outln(String::format("Format first arg => {0} and second arg => {1}",1,2)) 3 | Console::outln(String::format("Format first arg => {0} and another first arg => {0}",1)) 4 | Console::outln(String::format("Padding 2 0s => {0:d2}",1)) 5 | Console::outln(String::format("Padding 4 0s => {0:d4}",1)) 6 | Console::outln(String::format("Padding 2 spaces => {0,2}",1)) 7 | Console::outln(String::format("Padding 4 spaces => {0,4}",1)) -------------------------------------------------------------------------------- /doc/examples/language/string/string_format_out.zs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jespa007/zetscript/d73cbd8bc85437a5a776e8b6e0bba447749fc1b7/doc/examples/language/string/string_format_out.zs -------------------------------------------------------------------------------- /doc/examples/language/string/string_index_of.zs: -------------------------------------------------------------------------------- 1 | var s="The quick brown fox jumps over the lazy dog."; 2 | Console::outln("s => '{0}'",s) 3 | Console::outln("s.indexOf(\"fo\") => {0}",s.indexOf("fo")) 4 | Console::outln("s.indexOf(\"foy\") => {0}",s.indexOf("foy")) -------------------------------------------------------------------------------- /doc/examples/language/string/string_insert_at.zs: -------------------------------------------------------------------------------- 1 | var s="hell wd"; 2 | 3 | Console::outln("s => '{0}'",s); 4 | s.insertAt(4,'o') 5 | Console::outln("s.insertAt(4,'o') => '{0}'",s) 6 | s.insertAt(7,"orl") 7 | Console::outln("s.insertAt(7,\"orl\") => '{0}'",s) -------------------------------------------------------------------------------- /doc/examples/language/string/string_length.zs: -------------------------------------------------------------------------------- 1 | Console::outln("hello world".length) -------------------------------------------------------------------------------- /doc/examples/language/string/string_replace.zs: -------------------------------------------------------------------------------- 1 | var s="My blue car with blue door and blue wheel" 2 | Console::outln("s => '{0}'",s) 3 | Console::outln("s.replace(\"blue\",\"green\") => '{0}'",s.replace("blue","green")) -------------------------------------------------------------------------------- /doc/examples/language/string/string_split.zs: -------------------------------------------------------------------------------- 1 | var s="The quick brown fox jumps over the lazy dog."; 2 | Console::outln("s => '{0}'",s) 3 | Console::outln("s.split(' ') => {0}",s.split(' ')) 4 | Console::outln("s.split(\"jumps\") => {0}",s.split("jumps")) -------------------------------------------------------------------------------- /doc/examples/language/string/string_starts_with.zs: -------------------------------------------------------------------------------- 1 | var s = "Hello"; 2 | Console::outln("s => '{0}'", s) 3 | Console::outln("s.startsWith(\"Hel\") => '{0}'", s.startsWith("Hel")); 4 | Console::outln("s.startsWith(\"llo\") => '{0}'",s.startsWith("llo")); 5 | Console::outln("s.startsWith(\"o\") => '{0}'",s.startsWith("o")); -------------------------------------------------------------------------------- /doc/examples/language/string/string_substring.zs: -------------------------------------------------------------------------------- 1 | var s="hello world"; 2 | Console::outln("s.substring(0) => '{0}'",s.substring(0)) 3 | Console::outln("s.substring(3) => '{0}'",s.substring(3)) 4 | Console::outln("s.substring(2,3) => '{0}'",s.substring(2,3)) 5 | Console::outln("s.substring(3,-2) => '{0}'",s.substring(3,-2)) 6 | -------------------------------------------------------------------------------- /doc/examples/language/string/string_to_lower_case.zs: -------------------------------------------------------------------------------- 1 | var s="Hello World"; 2 | Console::outln("s => '{0}'",s.toLowerCase()); 3 | Console::outln("s.toLowerCase() => '{0}'",s.toLowerCase()); 4 | -------------------------------------------------------------------------------- /doc/examples/language/string/string_to_upper_case.zs: -------------------------------------------------------------------------------- 1 | var s="Hello World"; 2 | Console::outln("s => '{0}'",s) 3 | Console::outln("s.toUpperCase() => '{0}'",s.toUpperCase()) 4 | -------------------------------------------------------------------------------- /doc/examples/language/system/system_clock.zs: -------------------------------------------------------------------------------- 1 | while(System::clock() < 1){ 2 | var start=System::clock() 3 | while((System::clock()-start) < 0.1){} 4 | Console::outln("Ellapsed seconds: {0}",System::clock()); 5 | } -------------------------------------------------------------------------------- /doc/examples/language/system/system_eval.zs: -------------------------------------------------------------------------------- 1 | Console::outln(System::eval( 2 | "return op1+op2;\n" 3 | ,{ 4 | op1:5 5 | ,op2:10 6 | }) 7 | ); 8 | 9 | -------------------------------------------------------------------------------- /doc/examples/language/type/type_instanceof.zs: -------------------------------------------------------------------------------- 1 | class A{} 2 | class B extends A{} 3 | 4 | Console::outln("10 instanceof Integer => " + 10 instanceof Integer) 5 | Console::outln("10 instanceof Float => " + 10 instanceof Float) 6 | Console::outln("10.5 instanceof Integer => "+ 10.5 instanceof Integer) 7 | Console::outln("10.5 instanceof Float => "+ 10.5 instanceof Float) 8 | Console::outln("\"string\" instanceof String => "+ "string" instanceof String) 9 | Console::outln("[] instanceof Array => "+ [] instanceof Array) 10 | Console::outln("{} instanceof Object => "+ {} instanceof Object) 11 | Console::outln("function(){} instanceof Function => "+ function(){} instanceof Function) 12 | Console::outln("new A() instanceof A => "+ new A() instanceof A) 13 | Console::outln("new B() instanceof A => "+ new B() instanceof A) 14 | Console::outln("new A() instanceof B => "+ new A() instanceof B) 15 | -------------------------------------------------------------------------------- /doc/examples/language/type/type_typeof.zs: -------------------------------------------------------------------------------- 1 | class A{} 2 | 3 | Console::outln("typeof 10 => " + typeof 10) 4 | Console::outln("typeof 10.5 => "+ typeof 10.5) 5 | Console::outln("typeof \"string\" => "+ typeof "string") 6 | Console::outln("typeof [] => "+ typeof []) 7 | Console::outln("typeof {} => "+ typeof {}) 8 | Console::outln("typeof function(){} => "+ typeof function(){}) 9 | Console::outln("typeof new A() => "+ typeof new A()) 10 | 11 | -------------------------------------------------------------------------------- /doc/generate-html.sh: -------------------------------------------------------------------------------- 1 | asciidoctor -a stylesdir=`pwd`/resources/css -a stylesheet=zetscript-reference-manual.css adoc/zetscript-reference-manual.adoc -o zetscript-reference-manual.html 2 | -------------------------------------------------------------------------------- /doc/generate-pdf.sh: -------------------------------------------------------------------------------- 1 | asciidoctor-pdf -a pdf-theme=zetscript-reference-manual.yml -a pdf-themesdir=resources/yml adoc/zetscript-reference-manual.adoc -o zetscript-reference-manual.pdf 2 | -------------------------------------------------------------------------------- /doc/prefaces/preface_1_historic_version.adoc: -------------------------------------------------------------------------------- 1 | Historic version 2 | ---------------- 3 | 4 | |==== 5 | |Version |Zetscript version |Author | Description 6 | |1.00 7 | |1.1.3 8 | |Jordi Espada 9 | |First version 10 | 11 | |1.01 12 | |1.2.0 13 | |Jordi Espada 14 | |Changes since 1.2.0 15 | 16 | |1.03 17 | |1.3.0 18 | |Jordi Espada 19 | |Changes since 1.3.0 20 | 21 | |2.00 22 | |2.0.0 23 | |Jordi Espada 24 | |Changes from 2.0.0 25 | |==== 26 | 27 | -------------------------------------------------------------------------------- /samples/api/MyClass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class MyClass{ 4 | public: 5 | int data1; 6 | int data2; 7 | int data3; 8 | 9 | MyClass(){ 10 | this->data1=5; 11 | this->data2=10; 12 | this->data3=20; 13 | } 14 | 15 | void function0(){ 16 | printf("function0\n"); 17 | } 18 | 19 | void function1(int arg){ 20 | this->data1 = arg; 21 | printf("int argument is %i\n",this->data1); 22 | } 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /samples/api/MyClassExtend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class MyClassExtend:public MyClass{ 4 | public: 5 | zetscript::zs_float data4; 6 | 7 | void function2(float arg){ 8 | this->data4 = arg; 9 | printf("Float argument is %.02f\n",this->data4); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /samples/api/helloworld.cpp: -------------------------------------------------------------------------------- 1 | #include "zetscript.h" 2 | 3 | void sayHelloWorld(zetscript::ScriptEngine *_script_engine){ 4 | printf("Hello world from ZetScript\n"); 5 | } 6 | 7 | int main(){ 8 | zetscript::ScriptEngine script_engine; 9 | script_engine.registerFunction("sayHelloWorld",sayHelloWorld); 10 | script_engine.compileAndRun("sayHelloWorld()"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /samples/api/register_constant.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "zetscript.h" 3 | 4 | int main(){ 5 | 6 | // instance ScriptEngine 7 | zetscript::ScriptEngine script_engine; 8 | 9 | script_engine.registerConstantInteger("MY_CONSTANT_INT",10); 10 | script_engine.registerConstantString("MY_CONSTANT_STR","my_string"); 11 | script_engine.registerConstantBoolean("MY_CONSTANT_BOOL",true); 12 | script_engine.registerConstantFloat("MY_CONSTANT_FLOAT",2.5e-3); 13 | 14 | script_engine.compileAndRun( 15 | "Console::outln(\"MY_CONSTANT_INT:\"+MY_CONSTANT_INT);\n" 16 | "Console::outln(\"MY_CONSTANT_STR:\"+MY_CONSTANT_STR);\n" 17 | "Console::outln(\"MY_CONSTANT_BOOL:\"+MY_CONSTANT_BOOL);\n" 18 | "Console::outln(\"MY_CONSTANT_FLOAT:\"+MY_CONSTANT_FLOAT);\n" 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /samples/language/class_property.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | 3 | // attributes 4 | a{ 5 | _set(value){ 6 | this.__attrib_a__=value; 7 | } 8 | _get(){ 9 | return this.__attrib_a__; 10 | } 11 | } 12 | 13 | b{ 14 | _set(value){ 15 | this.__attrib_b__=value; 16 | } 17 | _get(){ 18 | return this.__attrib_b__; 19 | } 20 | } 21 | } 22 | 23 | 24 | 25 | var a=new A(); 26 | a.a=1; 27 | System::assert(a.a==1,"a.a!=1"); 28 | a.b=2 29 | System::assert(a.b==2,"a.b!=2"); 30 | 31 | 32 | -------------------------------------------------------------------------------- /samples/language/clock.zs: -------------------------------------------------------------------------------- 1 | var start=System::clock(); 2 | 3 | while((System::clock()-start) < 1){ 4 | var subtime_start=System::clock() 5 | while((System::clock()-subtime_start) < 0.1){} 6 | Console::outln("Ellapsed seconds: {0}",System::clock()-start); 7 | } -------------------------------------------------------------------------------- /samples/language/datetime.zs: -------------------------------------------------------------------------------- 1 | var now=DateTime::now(); // now 2 | var utc=DateTime::nowUtc(); // utc 3 | 4 | Console::outln("utc:{0}",utc) 5 | Console::outln("now:{0}",now) 6 | 7 | now.addDays(1) 8 | Console::outln("Added one day:{0}",now) 9 | 10 | now.addMonths(1) 11 | Console::outln("Added one month:{0}",now) 12 | 13 | now.addYears(1) 14 | Console::outln("Added one year:{0}",now) -------------------------------------------------------------------------------- /samples/language/factorial.zs: -------------------------------------------------------------------------------- 1 | function factorial(n){ 2 | if (n == 0) { 3 | return 1; 4 | }else{ 5 | return n * factorial(n - 1); 6 | } 7 | } 8 | 9 | Console::outln("f:"+factorial(5)); -------------------------------------------------------------------------------- /samples/language/fib.zs: -------------------------------------------------------------------------------- 1 | function fibR(n) { 2 | if (n < 2) { 3 | return n 4 | } 5 | return fibR(n-2)+fibR(n-1) 6 | } 7 | 8 | for(var i=0; i <10; i++) 9 | { 10 | var start=System::clock() 11 | Console::outln("fib: {0} time: {1} s", fibR(34),System::clock()-start); 12 | } 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /samples/language/function_arg_by_ref.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | _tostring(){ 3 | return "custom string"; 4 | } 5 | }; 6 | 7 | 8 | 9 | var functions=[ 10 | function(a,b,c){ 11 | // overwrite argument values 12 | Console::outln("function passing args by copy"); 13 | a=0; 14 | b=0; 15 | c=0; 16 | Console::outln("in function post a:"+a+" b:"+b+" c:"+c); 17 | },function(ref a,ref b, ref c){ 18 | // overwrite value refs 19 | Console::outln("function passing args by ref"); 20 | a=0; 21 | b=0; 22 | c=0; 23 | Console::outln("in function post a:"+a+" b:"+b+" c:"+c); 24 | } 25 | ]; 26 | 27 | 28 | for(var i=0; i < functions.length; i++) 29 | { 30 | var a=10,b=10,c=new A(); 31 | 32 | Console::outln("----"); 33 | Console::outln("before call a:"+a+" b:"+b+" c:"+c); 34 | 35 | functions[i](a,b,c); 36 | 37 | Console::outln("after call a:"+a+" b:"+b+" c:"+c); 38 | } 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /samples/language/function_arg_default.zs: -------------------------------------------------------------------------------- 1 | function f(a,b=0,c){ 2 | Console::outln("{0} {1} {2}",a,b,c) 3 | } 4 | 5 | f(0) 6 | 7 | -------------------------------------------------------------------------------- /samples/language/helloworld.zs: -------------------------------------------------------------------------------- 1 | Console::outln("hello world!"); -------------------------------------------------------------------------------- /samples/language/if_else.zs: -------------------------------------------------------------------------------- 1 | var n=-1; 2 | 3 | if(n<10){ 4 | Console::outln("n < 10"); 5 | }else if(n<20){ 6 | Console::outln("n < 20"); 7 | }else{ 8 | Console::outln("n >=20"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /samples/language/import.zs: -------------------------------------------------------------------------------- 1 | import "import/C.zs" 2 | 3 | var c= new C(); // initializes data2 as 3.0 and return the value 4 | 5 | c.function1(); -------------------------------------------------------------------------------- /samples/language/import/A.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | function function1(){ 3 | Console::outln("call from A"); 4 | } 5 | }; -------------------------------------------------------------------------------- /samples/language/import/B.zs: -------------------------------------------------------------------------------- 1 | import "A.zs" 2 | 3 | class B extends A{ 4 | function function1(){ 5 | super(); 6 | Console::outln("call from B"); 7 | } 8 | }; -------------------------------------------------------------------------------- /samples/language/import/C.zs: -------------------------------------------------------------------------------- 1 | import "B.zs" 2 | 3 | class C extends B{ 4 | function function1(){ 5 | super(); 6 | Console::outln("call from C"); 7 | } 8 | }; -------------------------------------------------------------------------------- /samples/language/in.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | _in(k){ 3 | if(k<10 || k > 20){ 4 | return false; 5 | } 6 | return true; 7 | } 8 | 9 | } 10 | 11 | var b1=false 12 | var b2=true 13 | var s1="abc" 14 | 15 | var i=10 16 | var test_in=[ 17 | "0 in [3,2,1,1,0]" 18 | ,"20 in [3,2,1,1,0]" 19 | ,"s1 in [3,2,1,1,\"abcd\",0]" 20 | ,"s1 in [3,2,1,1,\"abc\",0]" 21 | ,"b1 in [3,2,1,1,\"abc\",0,true]" 22 | ,"b2 in [3,2,1,1,\"abc\",0,false]" 23 | ,"b1 in [3,2,1,1,\"abc\",0,false]" 24 | ,"b2 in [3,2,1,1,\"abc\",0,true]" 25 | ,"\"a\" in {k:'a',a:0}" 26 | ,"\"b\" in {k:'a',a:0}" 27 | ,"\"abc\" in \"aaaabcdef\"" 28 | ,"\"abce\" in \"aaaabcdef\"" 29 | ,"'a' in \"jdkjakdkk\"" 30 | ,"'b' in \"jdkjakdkk\"" 31 | ,"i in new A()" 32 | ,"0 in new A()" 33 | ]; 34 | 35 | 36 | for(var v in test_in){ 37 | Console::outln("{0}:{1}",v,System::eval(v)) 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /samples/language/instance_by_value.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | A(){ 3 | Console::outln("instance from A") 4 | } 5 | } 6 | 7 | // it loads type of A into variable type_a 8 | var type_a=A; 9 | 10 | 11 | // it can create instances from vars that contains a type 12 | new type_a(); 13 | 14 | if(type_a == A){ 15 | Console::outln("type_a is typeof A") 16 | } 17 | 18 | -------------------------------------------------------------------------------- /samples/language/instanceof.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | 3 | } 4 | 5 | class B extends A{ 6 | 7 | 8 | } 9 | 10 | class C{ 11 | 12 | } 13 | 14 | var test_instanceof=[ 15 | "0 instanceof int" 16 | ,"0.0 instanceof float" 17 | ,"true instanceof bool" 18 | ,"[0,1,2] instanceof Array" 19 | ,"\"abc\" instanceof String" 20 | ,"new A() instanceof A" 21 | ,"new B() instanceof A" 22 | ,"new B() instanceof B" 23 | ,"new C() instanceof B" 24 | ,"{a:0,b:1} instanceof ScriptObject" 25 | 26 | ]; 27 | 28 | 29 | for(var v in test_instanceof){ 30 | Console::outln("{0}:{1}",v,System::eval(v)) 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /samples/language/loops.zs: -------------------------------------------------------------------------------- 1 | 2 | // for 3 | Console::outln("test for:"); 4 | for(var i=0,j=0;i < 10; i++,j+=2){ 5 | Console::outln("i:"+i+" j:"+j); 6 | } 7 | 8 | Console::outln("test while:"); 9 | var k=0; 10 | while(k < 10){ 11 | Console::outln("k:"+k++); 12 | } 13 | 14 | Console::outln("test do-while:"); 15 | k=0; 16 | do{ 17 | Console::outln("k:"+k++); 18 | }while(k<10); -------------------------------------------------------------------------------- /samples/language/prime.zs: -------------------------------------------------------------------------------- 1 | function isprime(n) 2 | { 3 | for (var i = 2; i < n; ++i){ 4 | if (n % i == 0){ 5 | return false; 6 | } 7 | } 8 | return true; 9 | } 10 | 11 | function primes(n) 12 | { 13 | var count = 0; 14 | for (var i = 2; i <= n; ++i){ 15 | if (isprime(i)){ 16 | ++count; 17 | } 18 | } 19 | return count; 20 | } 21 | 22 | var start=System::clock(); 23 | Console::outln("primes: " + primes(200000) + " time:"+(System::clock()-start)+"ms"); -------------------------------------------------------------------------------- /samples/language/sum.zs: -------------------------------------------------------------------------------- 1 | var sum = 0.0; 2 | 3 | for (var i = 1; i <= 1000000; ++i) { 4 | if (i % 2 == 0) { 5 | sum += 1.0 / i; 6 | } 7 | else { 8 | sum += 1.0 / ((i) * i); 9 | } 10 | } 11 | Console::outln("number:"+sum); 12 | -------------------------------------------------------------------------------- /samples/language/typeof.zs: -------------------------------------------------------------------------------- 1 | class A{} 2 | 3 | var a=new A() 4 | 5 | var test_typeof=[ 6 | "typeof 0" 7 | ,"typeof 1.0" 8 | ,"typeof true" 9 | ,"typeof [0,1,2]" 10 | ,"typeof {a:0,b:1}" 11 | ,"typeof a" 12 | ]; 13 | 14 | 15 | for(var i in test_typeof){ 16 | Console::outln("{0}:{1}",i,System::eval("return" +i)) 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | /base/Config.h -------------------------------------------------------------------------------- /src/base/@base.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "System.cpp" 6 | #include "Character.cpp" 7 | #include "File.cpp" 8 | #include "Buffer.cpp" 9 | #include "Log.cpp" 10 | #include "Path.cpp" 11 | #include "Rtti.cpp" 12 | #include "String.cpp" 13 | #include "MapIntIterator.cpp" 14 | #include "MapInt.cpp" 15 | #include "MapStringIterator.cpp" 16 | #include "MapString.cpp" 17 | #include "Directory.cpp" 18 | #include "TimeSpan.cpp" 19 | #include "DateTime.cpp" 20 | #include "Console.cpp" 21 | #include "Memory.cpp" 22 | #include "Exception.cpp" 23 | #include "Integer.cpp" 24 | #include "Float.cpp" 25 | #include "Boolean.cpp" 26 | -------------------------------------------------------------------------------- /src/base/Boolean.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "@base.h" 6 | 7 | namespace zetscript{ 8 | bool * Boolean::parse(const String & _str){ 9 | String str=_str.toLowerCase(); 10 | 11 | if(str=="true"){ 12 | bool *b=new bool; 13 | *b=true; 14 | return b; 15 | 16 | }else if(str=="false"){ 17 | bool *b=new bool; 18 | *b=false; 19 | return b; 20 | } 21 | 22 | // TODO: develop exception handler. 23 | return NULL; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/base/Boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | class Boolean{ 10 | public: 11 | static bool * parse(const String & s); 12 | 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /src/base/Buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | #include "@base.h" 8 | 9 | namespace zetscript{ 10 | Buffer::Buffer(uint8_t *_ptr,int _ptr_len){ 11 | ptr=_ptr; 12 | ptr_len=_ptr_len; 13 | } 14 | 15 | Buffer::~Buffer(){ 16 | if(ptr != NULL){ 17 | free(ptr); 18 | } 19 | ptr=NULL; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/base/Buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | class Buffer{ 10 | public: 11 | uint8_t *ptr; 12 | int ptr_len; 13 | Buffer(uint8_t *ptr,int ptr_len); 14 | ~Buffer(); 15 | }; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/base/Character.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "@base.h" 6 | 7 | namespace zetscript{ 8 | 9 | char Character::toLowerCase(char _ch){ 10 | if('A' <= _ch && _ch <= 'Z'){ 11 | //Only if it's a upper letter 12 | return 'a'+(_ch-'A'); 13 | } 14 | return _ch; 15 | } 16 | 17 | char Character::toUpperCase(char _ch){ 18 | if('a' <= _ch && _ch <= 'z'){ 19 | //Only if it's a upper letter 20 | return 'A'+(_ch-'a'); 21 | } 22 | return _ch; 23 | } 24 | 25 | bool Character::isDigit(char _c){ 26 | return (('0' <= _c) && (_c<='9')); 27 | } 28 | 29 | bool Character::isHexaDigit(char _c){ 30 | return ((('0' <= _c) && (_c<='9')) || ('a'<=(Character::toLowerCase(_c))&&(Character::toLowerCase(_c)<='f'))); 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/base/Character.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | class Character{ 10 | public: 11 | static char toLowerCase(char _c); 12 | static char toUpperCase(char _c); 13 | static bool isDigit(char _c); 14 | static bool isHexaDigit(char _c); 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /src/base/Console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | class Console{ 9 | public: 10 | 11 | static int getline(char **lineptr, size_t *n, FILE *stream); 12 | static char readChar(); 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /src/base/Directory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | namespace Directory{ 9 | bool changeDir(const String & path); 10 | String getCurrentDirectory(); 11 | bool exists(const String & _dir); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/base/File.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | namespace File{ 9 | 10 | bool exists(const String & _file); 11 | Buffer *readText(const String & _filename); 12 | int size(const String & _filename); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/base/Float.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "@base.h" 6 | 7 | namespace zetscript{ 8 | 9 | 10 | zs_float * Float::parse(const String & s){ 11 | 12 | char *end; 13 | char *data=(char *)s.toConstChar(); 14 | float l; 15 | errno = 0; 16 | l = strtof(data, &end); 17 | 18 | if (end == data){ 19 | return NULL; 20 | }else if ((errno == ERANGE && l == FLT_MAX) || l > FLT_MAX) { 21 | return NULL; 22 | }else if ((errno == ERANGE && l < FLT_MIN) /* || l < FLT_MIN*/) { 23 | return NULL; 24 | } 25 | if (*s.toConstChar() == '\0' || *end != '\0') { 26 | return NULL; 27 | } 28 | 29 | return new zs_float(l); 30 | } 31 | 32 | String Float::toString(zs_float _number){ 33 | 34 | char float_str[100000]; 35 | 36 | sprintf(float_str,"%f",_number); 37 | 38 | return String(float_str); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/base/Float.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | class Float{ 10 | public: 11 | static zs_float * parse(const String & ); 12 | static String toString(zs_float _number); 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /src/base/Integer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | class Integer{ 10 | public: 11 | 12 | typedef enum{ 13 | INTEGER_TYPE_INVALID=0, 14 | INTEGER_TYPE_HEXA, 15 | INTEGER_TYPE_BINARY, 16 | INTEGER_TYPE_INT, 17 | }IntegerType; 18 | 19 | 20 | static zs_int * parse(const String & ); 21 | static String toString(zs_int _number, const String & _format=""); 22 | 23 | private: 24 | static IntegerType isInteger(const String & test_str); 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /src/base/List.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | template 10 | struct ListNode{ 11 | _N data; 12 | ListNode *previous, *next; 13 | 14 | ListNode(){ 15 | previous=next=NULL; 16 | } 17 | }; 18 | 19 | template 20 | class List{ 21 | public: 22 | 23 | ListNode<_N> *first, *last; 24 | 25 | List(); 26 | 27 | void insert(ListNode<_N> * _node); 28 | void remove(ListNode<_N> * _node); 29 | void dettachAllNodes(void (*_dettachNode)(ListNode<_N> *)=NULL); 30 | 31 | ~List(); 32 | 33 | }; 34 | } 35 | 36 | #include "List.tcc" 37 | -------------------------------------------------------------------------------- /src/base/MapIntIterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | class MapInt; 9 | struct MapIntNode; 10 | class MapIntIterator{ 11 | public: 12 | 13 | zs_int key; 14 | zs_int value; 15 | 16 | 17 | MapIntIterator(); 18 | MapIntIterator(MapInt *map); 19 | void next(); 20 | bool end(); 21 | 22 | 23 | private: 24 | MapIntNode *current_node; 25 | MapInt *map; 26 | bool _end; 27 | 28 | 29 | void setup(); 30 | void setCurrentPair(); 31 | }; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/base/MapStringIterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | class MapString; 9 | struct MapStringNode; 10 | class MapStringIterator{ 11 | public: 12 | 13 | const char *key; 14 | zs_int value; 15 | 16 | 17 | MapStringIterator(); 18 | MapStringIterator(MapString *map); 19 | void next(); 20 | bool end(); 21 | 22 | 23 | private: 24 | MapStringNode *current_node; 25 | MapString *map; 26 | bool _end; 27 | 28 | 29 | void setup(); 30 | void setCurrentPair(); 31 | }; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/base/Memory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "@base.h" 6 | 7 | namespace zetscript{ 8 | 9 | void *zs_malloc(size_t _size,const char *_file, int _line){ 10 | void *p=NULL; 11 | #ifdef __MEMMANAGER__ 12 | p=MEMMGR_malloc(_size,_file,_line); 13 | #else 14 | ZS_UNUSUED_2PARAMS(_file, _line); 15 | p=malloc(_size); 16 | #endif 17 | memset(p,0,_size); 18 | return p; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/base/Memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | #define ZS_MALLOC(s) zetscript::zs_malloc(s,__FILE__,__LINE__) 8 | 9 | namespace zetscript{ 10 | void *zs_malloc(size_t _size,const char *_file, int _line); 11 | } 12 | -------------------------------------------------------------------------------- /src/base/Path.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | class Path{ 9 | public: 10 | static String getDirectory(const String & _path); 11 | static String getFilename(const String & _path); 12 | static String getFilenameWithoutExtension(const String & _path); 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /src/base/Rtti.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | class Rtti{ 9 | public: 10 | static String demangle(const char * name); 11 | 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /src/base/System.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | namespace zetscript{ 6 | class System{ 7 | public: 8 | static zs_float clock(); 9 | static const char * getIoErrorCodeDetails(int _error_code); 10 | static const char * getErrorCodeDetails(int _error_code); 11 | static int getLastError(); 12 | 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /src/core/ByteCodeHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | 6 | #pragma once 7 | 8 | namespace zetscript{ 9 | 10 | class ByteCodeHelper{ 11 | public: 12 | static const char * getByteCodeName(ByteCode _byte_code); 13 | static const char * getByteCodeOperatorName(ByteCode _byte_code); 14 | }; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/core/MetamethodHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Metamethod.h" 9 | 10 | namespace zetscript{ 11 | 12 | class MetamethodHelper{ 13 | public: 14 | 15 | static const char * getMetamethodOperatorName(Metamethod _metamethod); 16 | static const char * getMetamethodSymbolName(Metamethod _metamethod); 17 | static int getMetamethodNumberArguments(Metamethod _metamethod); 18 | static bool isMetamethodStatic(Metamethod _metamethod); 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/core/StackElementMemberProperty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | 8 | namespace zetscript{ 9 | 10 | class MemberProperty; 11 | class ScriptObject; 12 | struct StackElementMemberProperty{ 13 | public: 14 | MemberProperty *member_property; 15 | ScriptObject *so_object; 16 | 17 | StackElementMemberProperty( 18 | ScriptObject *_so_object 19 | ,MemberProperty *_member_property){ 20 | so_object = _so_object; 21 | member_property= _member_property; 22 | } 23 | }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/core/object/ArrayIteratorScriptObjectZs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "zetscript.h" 6 | 7 | namespace zetscript{ 8 | 9 | void ArrayIteratorObjectZs_get(ScriptEngine *_script_engine,ArrayIteratorScriptObject *vi){ 10 | ZS_UNUSUED_PARAM(_script_engine); 11 | vi->get(); 12 | } 13 | 14 | void ArrayIteratorObjectZs_next(ScriptEngine *_script_engine,ArrayIteratorScriptObject *vi){ 15 | ZS_UNUSUED_PARAM(_script_engine); 16 | vi->next(); 17 | } 18 | 19 | bool ArrayIteratorObjectZs_end(ScriptEngine *_script_engine,ArrayIteratorScriptObject *vi){ 20 | ZS_UNUSUED_PARAM(_script_engine); 21 | return vi->end(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/core/object/ArrayIteratorScriptObjectZs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | namespace zetscript{ 6 | void ArrayIteratorObjectZs_get(ScriptEngine *_script_engine,ArrayIteratorScriptObject *vi); 7 | void ArrayIteratorObjectZs_next(ScriptEngine *_script_engine,ArrayIteratorScriptObject *vi); 8 | bool ArrayIteratorObjectZs_end(ScriptEngine *_script_engine,ArrayIteratorScriptObject *vi); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/core/object/ClassScriptObject.tcc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | 6 | namespace zetscript{ 7 | 8 | template 9 | _C ClassScriptObject::to(){ 10 | const char * native_name = typeid(_C).name(); 11 | int id=ZS_UNDEFINED_IDX; 12 | if((id=script_engine->getScriptTypesFactory()->getScriptTypeIdFromNamePtr(native_name))==ZS_UNDEFINED_IDX){ 13 | ZS_THROW_RUNTIME_ERROR( 14 | "Cannot instance script object as native type '%s' because is not registered" 15 | ,Rtti::demangle(typeid(_C).name()).toConstChar() 16 | ); 17 | } 18 | 19 | return (_C)this->getNativeObject(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/core/object/MemberFunctionScriptObject.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "zetscript.h" 6 | 7 | namespace zetscript{ 8 | 9 | MemberFunctionScriptObject * MemberFunctionScriptObject::newObjectMemberFunction(ScriptEngine *_script_engine, ScriptObject *_so_object_ref, ScriptFunction *_sf_ref){ 10 | 11 | return new MemberFunctionScriptObject(_script_engine,_so_object_ref,_sf_ref); 12 | } 13 | 14 | MemberFunctionScriptObject::MemberFunctionScriptObject( 15 | zetscript::ScriptEngine *_script_engine 16 | , ScriptObject *_so_ref 17 | , ScriptFunction *_sf_ref 18 | ):RefScriptObject(_script_engine, _so_ref){ 19 | script_type_id=SCRIPT_TYPE_ID_MEMBER_FUNCTION_SCRIPT_OBJECT; 20 | this->sf_ref=_sf_ref; 21 | } 22 | 23 | 24 | 25 | MemberFunctionScriptObject::~MemberFunctionScriptObject(){ 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/core/object/ObjectIteratorScriptObjectZs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "zetscript.h" 6 | 7 | namespace zetscript{ 8 | void ObjectIteratorScriptObjectZs_next(ScriptEngine *_script_engine,ObjectIteratorScriptObject *oi){ 9 | ZS_UNUSUED_PARAM(_script_engine); 10 | oi->next(); 11 | } 12 | 13 | void ObjectIteratorScriptObjectZs_get(ScriptEngine *_script_engine,ObjectIteratorScriptObject *oi){ 14 | ZS_UNUSUED_PARAM(_script_engine); 15 | oi->get(); 16 | } 17 | 18 | 19 | bool ObjectIteratorScriptObjectZs_end(ScriptEngine *_script_engine,ObjectIteratorScriptObject *oi){ 20 | ZS_UNUSUED_PARAM(_script_engine); 21 | return oi->end(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/core/object/ObjectIteratorScriptObjectZs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | namespace zetscript{ 6 | 7 | void ObjectIteratorScriptObjectZs_get(ScriptEngine *_script_engine,ObjectIteratorScriptObject *oi); 8 | void ObjectIteratorScriptObjectZs_next(ScriptEngine *_script_engine,ObjectIteratorScriptObject *oi); 9 | bool ObjectIteratorScriptObjectZs_end(ScriptEngine *_script_engine,ObjectIteratorScriptObject *oi); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/core/object/ObjectScriptObjectZs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | namespace zetscript{ 6 | class ObjectIteratorScriptObject; 7 | 8 | ArrayScriptObject * ObjectScriptObjectZs_keys(ScriptEngine *_script_engine,ObjectScriptObject *o1); 9 | bool ObjectScriptObjectZs_contains(ScriptEngine *_script_engine,ObjectScriptObject *o1, String * key); 10 | void ObjectScriptObjectZs_clear(ScriptEngine *_script_engine,ObjectScriptObject *o1); 11 | void ObjectScriptObjectZs_erase(ScriptEngine *_script_engine,ObjectScriptObject *o1, String * key); 12 | ObjectIteratorScriptObject * ObjectScriptObjectZs_iter(ScriptEngine *_script_engine,ObjectScriptObject *oo); 13 | void ObjectScriptObjectZs_extend(ScriptEngine *_script_engine,ObjectScriptObject *o1,ObjectScriptObject *o2); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/core/object/RefScriptObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | namespace zetscript{ 6 | 7 | class RefScriptObject : public ScriptObject{ 8 | public: 9 | RefScriptObject(ScriptEngine *_script_engine, ScriptObject *_so_ref); 10 | void setRefObject(ScriptObject *_ref_object); 11 | ScriptObject *getRefObject(); 12 | ~RefScriptObject(); 13 | 14 | 15 | protected: 16 | ListNode *ref_object_node; 17 | ScriptObject *ref_object; 18 | 19 | void dettachRefObject(); 20 | }; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/core/object/StringIteratorScriptObjectZs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "zetscript.h" 6 | 7 | namespace zetscript{ 8 | 9 | void StringIteratorScriptObjectZs_get(ScriptEngine *_script_engine,StringIteratorScriptObject *si){ 10 | ZS_UNUSUED_PARAM(_script_engine); 11 | si->get(); 12 | } 13 | 14 | void StringIteratorScriptObjectZs_next(ScriptEngine *_script_engine,StringIteratorScriptObject *si){ 15 | ZS_UNUSUED_PARAM(_script_engine); 16 | si->next(); 17 | } 18 | 19 | bool StringIteratorScriptObjectZs_end(ScriptEngine *_script_engine,StringIteratorScriptObject *si){ 20 | ZS_UNUSUED_PARAM(_script_engine); 21 | return si->end(); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/core/object/StringIteratorScriptObjectZs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | void StringIteratorScriptObjectZs_get(ScriptEngine *_script_engine,StringIteratorScriptObject *si); 9 | void StringIteratorScriptObjectZs_next(ScriptEngine *_script_engine,StringIteratorScriptObject *si); 10 | bool StringIteratorScriptObjectZs_end(ScriptEngine *_script_engine,StringIteratorScriptObject *si); 11 | } 12 | -------------------------------------------------------------------------------- /src/core/object/VarRefScriptObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | 8 | #define ZS_NEW_OBJECT_VAR_REF(script_engine,stk) VarRefObject::newVarRefObject(script_engine,stk) 9 | 10 | namespace zetscript{ 11 | 12 | class VarRefObject: public ScriptObject{ 13 | 14 | public: 15 | static VarRefObject * newVarRefObject(ScriptEngine *_script_engine, StackElement _stk_var_ref); // idx call 16 | VarRefObject(ScriptEngine *_script_engine); 17 | 18 | //void setIdxCall(int idx_call); 19 | //int getIdxCall(); 20 | StackElement *getStackElementPtr(); 21 | void setStackElement(StackElement stk); 22 | 23 | virtual String toString(); 24 | 25 | private: 26 | StackElement stk_var_ref; 27 | //int idx_call; 28 | void setup(); 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/module/@module.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "module/MathModule.cpp" 6 | #include "module/SystemModule.cpp" 7 | #include "module/JsonModule.cpp" 8 | #include "module/ConsoleModule.cpp" 9 | #include "module/TimeSpanModule.cpp" 10 | #include "module/DateTimeModule.cpp" 11 | -------------------------------------------------------------------------------- /src/module/@module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "module/MathModule.h" 6 | #include "module/SystemModule.h" 7 | #include "module/JsonModule.h" 8 | #include "module/ConsoleModule.h" 9 | #include "module/TimeSpanModule.h" 10 | #include "module/DateTimeModule.h" 11 | -------------------------------------------------------------------------------- /src/module/ConsoleModule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | class StringScriptObject; 10 | class ArrayScriptObject; 11 | class StringMod; 12 | 13 | zs_int ConsoleModule_readChar(ScriptEngine *_script_engine); 14 | void ConsoleModule_outln(ScriptEngine *_script_engine,StackElement *str, StackElement *args); 15 | void ConsoleModule_out(ScriptEngine *_script_engine,StackElement *str, StackElement *args); 16 | void ConsoleModule_errorln(ScriptEngine *_script_engine,StackElement *str, StackElement *args); 17 | void ConsoleModule_error(ScriptEngine *_script_engine,StackElement *str, StackElement *args); 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/module/JsonModule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | class ObjectScriptObject; 9 | class StringScriptObject; 10 | 11 | namespace json{ 12 | String serialize(ScriptEngine *_script_engine, StackElement *_stk, bool _is_formatted, bool _strict_json_format=true); 13 | } 14 | 15 | void JsonModule_deserialize(ScriptEngine *_script_engine,StringScriptObject *str_json); 16 | StringScriptObject * JsonModule_serialize(ScriptEngine *_script_engine,StackElement *stk,bool *minimized); 17 | StringScriptObject * JsonModule_serialize(ScriptEngine *_script_engine,StackElement *stk); 18 | } 19 | -------------------------------------------------------------------------------- /src/module/SystemModule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | class StringScriptObject; 10 | class ObjectScriptObject; 11 | class ArrayScriptObject; 12 | class StringMod; 13 | 14 | zs_float SystemModule_clock(ScriptEngine *_script_engine); 15 | void SystemModule_eval(ScriptEngine *_script_engine, StringScriptObject *_so_str_eval, ObjectScriptObject *_oo_param); 16 | void SystemModule_eval(ScriptEngine *_script_engine, StringScriptObject *_so_str_eval); 17 | void SystemModule_error(ScriptEngine *_script_engine, StackElement *str, StackElement *args); 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/module/TimeSpanModule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | namespace zetscript{ 8 | 9 | // member functions 10 | TimeSpan * TimeSpanModule_new(ScriptEngine *_script_engine); 11 | 12 | zs_int TimeSpanModule_get_seconds(ScriptEngine *_script_engine,TimeSpan *_this); 13 | zs_int TimeSpanModule_get_minutes(ScriptEngine *_script_engine,TimeSpan *_this); 14 | zs_int TimeSpanModule_get_hours(ScriptEngine *_script_engine,TimeSpan *_this); 15 | 16 | zs_int TimeSpanModule_get_days(ScriptEngine *_script_engine,TimeSpan *_this); 17 | 18 | void TimeSpanModule_delete(ScriptEngine *_script_engine,TimeSpan *_this); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/zetscript.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This _file is distributed under the MIT License. 3 | * See LICENSE _file for details. 4 | */ 5 | #pragma once 6 | 7 | #include "base/@base.h" 8 | #include "core/@core.h" 9 | #include "compiler/compiler.h" 10 | #include "vm/vm.h" 11 | #include "module/@module.h" 12 | #include "ScriptEngine.h" 13 | 14 | 15 | #define ZETSCRIPT_VERSION_MAJOR 2 16 | #define ZETSCRIPT_VERSION_MINOR 1 17 | #define ZETSCRIPT_VERSION_PATCH 0 18 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | test_all_config.h 2 | -------------------------------------------------------------------------------- /test/api/Number.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #pragma once 6 | 7 | 8 | class Number{ 9 | public: 10 | 11 | float value; 12 | 13 | Number(){ 14 | value=0; 15 | } 16 | 17 | Number(float _value){ 18 | value=_value; 19 | } 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /test/api/print_object_sizes.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #include "zetscript.h" 6 | 7 | int main(){ 8 | zetscript::ScriptEngine script_engine; 9 | script_engine.printAllStructSizes(); 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /test/language/benchmark/README.md: -------------------------------------------------------------------------------- 1 | # Benchmarks 2 | 3 | Time of executing all tasks in seconds for each language 4 | 5 | | Script | ZetScript 2.0.1 | Lua 5.3.6 | Python 3.10.12 | Wren 0.4.0 | Squirrel 3.2 | 6 | | ------------- | --------------- | ---------- | -------------- | -------------- | ------------- | 7 | | fib | 1.250 | 1.142 | 1.365 | 1.507 | 2.251 | 8 | | for | 0.593 | 0.066 | 0.138 | 0.181 | 0.151 | 9 | | map_strings | 12.020 | 0.125 | N/A | 0.183 | N/A | 10 | | string_equals | 0.266 | N/A | N/A | 0.380 | N/A | 11 | | binary_trees | 6.100 | N/A | N/A | 0.401 | N/A | 12 | -------------------------------------------------------------------------------- /test/language/benchmark/fib.lua: -------------------------------------------------------------------------------- 1 | function fib(n) 2 | if n < 2 then return n end 3 | return fib(n - 2) + fib(n - 1) 4 | end 5 | 6 | for i = 1, 10 do 7 | local start = os.clock() 8 | io.write(string.format("fib: %d time: %.8f\n",fib(34), os.clock() - start)) 9 | end 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/language/benchmark/fib.nut: -------------------------------------------------------------------------------- 1 | function fibR(n) { 2 | if (n < 2) { 3 | return n; 4 | } 5 | return fibR(n-2)+fibR(n-1); 6 | } 7 | 8 | for(local i=0; i < 10; i++){ 9 | local start=clock(); 10 | print("fib: "+fibR(34)+" time: "+(clock()-start)+" s\n"); 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/language/benchmark/fib.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def fib(n): 4 | if n <= 2: 5 | return 1 6 | else: 7 | return fib(n - 1) + fib(n - 2) 8 | 9 | 10 | for x in range(1,10): 11 | start_time = time.time() 12 | print("fib: %s time: %s s" % (fib(34),time.time() - start_time)) 13 | -------------------------------------------------------------------------------- /test/language/benchmark/fib.wren: -------------------------------------------------------------------------------- 1 | class Fib { 2 | static get(n) { 3 | if (n < 2) return n 4 | return get(n - 1) + get(n - 2) 5 | } 6 | } 7 | 8 | for (i in 1..10) { 9 | var start = System.clock 10 | System.print("fib: %(Fib.get(34)) time: %(System.clock - start)") 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/language/benchmark/fib.zs: -------------------------------------------------------------------------------- 1 | function fibR(n) { 2 | if (n < 2) { 3 | return n 4 | } 5 | return fibR(n-2)+fibR(n-1) 6 | } 7 | 8 | for(var i=0; i <10; i++) 9 | { 10 | var start=System::clock() 11 | Console::outln("fib: {0} time: {1} s", fibR(34),System::clock()-start); 12 | } 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/language/benchmark/for.lua: -------------------------------------------------------------------------------- 1 | 2 | function test_sum() 3 | local list = {} 4 | for i = 0, 999999 do 5 | list[i] = i 6 | end 7 | 8 | local sum = 0 9 | for k, i in pairs(list) do 10 | sum = sum + i 11 | end 12 | return sum 13 | end 14 | 15 | for i = 1, 10 do 16 | local start = os.clock() 17 | io.write(string.format("sum: %d time: %.8f\n",test_sum(), os.clock() - start)) 18 | end 19 | 20 | -------------------------------------------------------------------------------- /test/language/benchmark/for.nut: -------------------------------------------------------------------------------- 1 | function test_sum(){ 2 | 3 | local list = []; 4 | 5 | for (local i=0; i < 1000000; i++) { 6 | list.push(i); 7 | } 8 | 9 | local sum = 0; 10 | foreach (i in list) { 11 | sum = sum + i; 12 | } 13 | 14 | return sum; 15 | } 16 | 17 | for(local i=0; i < 10; i++){ 18 | local start=clock(); 19 | print("sum: "+test_sum()+" time: "+(clock()-start)+" s\n"); 20 | } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/language/benchmark/for.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import time 4 | 5 | # MapString "range" to an efficient range in both Python 2 and 3. 6 | try: 7 | range = xrange 8 | except NameError: 9 | pass 10 | 11 | def test_sum(): 12 | list = [] 13 | for i in range(0, 1000000): 14 | list.append(i) 15 | 16 | sum = 0 17 | for i in list: 18 | sum = sum + i 19 | 20 | return sum 21 | 22 | for i in range(0, 10): 23 | start = time.process_time() 24 | print("sum: "+str(test_sum())+" elapsed: " + str(time.process_time() - start)) 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/language/benchmark/for.wren: -------------------------------------------------------------------------------- 1 | class Sum { 2 | static test_sum() { 3 | var list = [] 4 | for (i in 0...1000000) list.add(i) 5 | 6 | var sum = 0 7 | for (i in list) sum = sum + i 8 | return sum 9 | } 10 | } 11 | 12 | 13 | for (i in 1..10) { 14 | var start = System.clock 15 | System.print("sum: %(Sum.test_sum()) time: %(System.clock - start)") 16 | } 17 | 18 | -------------------------------------------------------------------------------- /test/language/benchmark/for.zs: -------------------------------------------------------------------------------- 1 | function test_sum(){ 2 | 3 | var list = [] 4 | 5 | for (var i=0; i < 1000000; i++) { 6 | list.push(i) 7 | } 8 | 9 | var sum = 0 10 | for (var i in list) { 11 | sum = sum + i 12 | } 13 | 14 | return sum; 15 | } 16 | 17 | for(var i=0; i < 10; i++){ 18 | var start=System::clock(); 19 | Console::outln("sum: {0} elapsed: {1}",test_sum(),(System::clock() - start)) 20 | } -------------------------------------------------------------------------------- /test/language/import/A.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | constructor(_a){ 3 | this.a=_a 4 | } 5 | }; -------------------------------------------------------------------------------- /test/language/import/B.zs: -------------------------------------------------------------------------------- 1 | import "A.zs" 2 | 3 | class B extends A{ 4 | constructor(_a){ 5 | super(_a); 6 | this.a+=10 7 | } 8 | }; -------------------------------------------------------------------------------- /test/language/import/C.zs: -------------------------------------------------------------------------------- 1 | import "B.zs" 2 | 3 | class C extends B{ 4 | constructor(_a){ 5 | super(_a); 6 | this.a+=20 7 | } 8 | }; -------------------------------------------------------------------------------- /test/language/test_assert_error.zs: -------------------------------------------------------------------------------- 1 | System::assert(false,"test error") -------------------------------------------------------------------------------- /test/language/test_const.zs: -------------------------------------------------------------------------------- 1 | const c=[34+39,9,0]; // <-- demostrates const var 2 | 3 | class A{ 4 | const a=new A(); 5 | const b=11 6 | const d=A; 7 | }; 8 | 9 | // post declaration as const A::c 10 | const A::c=20 11 | 12 | System::assert(A::a instanceof A,"(A::a instanceof A)==false"); 13 | System::assert(A::b==11,"A::b!=11"); 14 | System::assert(A::c==20,"A::c!=10"); 15 | System::assert(A::d == A,"(A::d != A"); 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/language/test_constant_operations.zs: -------------------------------------------------------------------------------- 1 | System::assert(1+2+3+4==10,"1+2+3+4!=10") 2 | System::assert(10/5==2,"10/5!=2") 3 | System::assert(100*5-10/2==495,"100*5-10/2!=495") 4 | System::assert(1050-50-150==850,"100*5-10/2!=850") 5 | System::assert(5-10+10-10*10+90-10-5==-20,"5-10+10-100+5!=-90") 6 | 7 | -------------------------------------------------------------------------------- /test/language/test_cyclic_references.zs: -------------------------------------------------------------------------------- 1 | 2 | class B{ 3 | constructor(_a_ref){ 4 | this.a_ref=_a_ref; // cyclic reference by object 5 | this.b=this; 6 | } 7 | 8 | } 9 | 10 | class A{ 11 | constructor(){ 12 | this.b=new B(this) // cyclic reference 13 | this.v=[this,this.b] // cyclic reference 14 | this.a=this; 15 | 16 | } 17 | } 18 | 19 | 20 | new A() 21 | 22 | //System::asset(System::objectRefences()==0,"System::objectRefences()!=0"); 23 | 24 | -------------------------------------------------------------------------------- /test/language/test_eval.zs: -------------------------------------------------------------------------------- 1 | var v=System::eval("return a+b",{a:2,b:10}); 2 | System::assert(v==12,"v!=12") -------------------------------------------------------------------------------- /test/language/test_extends.zs: -------------------------------------------------------------------------------- 1 | 2 | class Entity{ 3 | // Member property 'name' (read and write) 4 | name{ 5 | // Implement metamethod _set (aka '=') 6 | _set(_name){ 7 | this.__name__=_name; 8 | } 9 | 10 | // Implement metamethod getter 11 | _get(){ 12 | return this.__name__; 13 | } 14 | } 15 | } 16 | 17 | class Player extends Entity{ 18 | constructor(){ 19 | // Calls constructor base (i.e Entity::constructor) 20 | this.name="Player"; 21 | } 22 | } 23 | 24 | var player=new Player(); 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/language/test_for_in_array.zs: -------------------------------------------------------------------------------- 1 | var v1=[1,"string",true] 2 | var sum_k=0 3 | var sum_v="" 4 | for(var v in v1){ 5 | sum_v+=v 6 | } 7 | 8 | System::assert(sum_v=="1stringtrue","sum_v!=1stringtrue") 9 | 10 | sum_k=0 11 | sum_v="" 12 | 13 | for(var k,v in v1){ 14 | sum_k+=k 15 | sum_v+=v 16 | } 17 | 18 | System::assert(sum_k==3,"sum_k!=3") 19 | System::assert(sum_v=="1stringtrue","sum_v!=1stringtrue") 20 | -------------------------------------------------------------------------------- /test/language/test_for_in_object.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:"string",c:true} 2 | var sum_k="",sum_v=""; 3 | 4 | for(var v in o){ 5 | sum_v+=v 6 | } 7 | 8 | System::assert(sum_v=="1stringtrue","sum_v!=1stringtrue") 9 | 10 | 11 | sum_k="" 12 | sum_v=""; 13 | 14 | for(var k,v in o){ 15 | sum_k+=k 16 | sum_v+=v 17 | } 18 | 19 | System::assert(sum_k=="abc","sum_k!=abc") 20 | System::assert(sum_v=="1stringtrue","sum_v!=1stringtrue") 21 | 22 | -------------------------------------------------------------------------------- /test/language/test_for_in_string.zs: -------------------------------------------------------------------------------- 1 | var str="abcd" 2 | var sum_k=0 3 | var sum_v=0 4 | 5 | for(var v in str){ 6 | sum_v+=v 7 | } 8 | 9 | System::assert(sum_v=='a'+'b'+'c'+'d',"sum_v!="+str) 10 | 11 | sum_k=0 12 | sum_v=0 13 | 14 | for(var k,v in str){ 15 | sum_k+=k 16 | sum_v+=v 17 | } 18 | 19 | System::assert(sum_k==6,"sum_k!=6") 20 | System::assert(sum_v=='a'+'b'+'c'+'d',"sum_v!="+str) 21 | 22 | -------------------------------------------------------------------------------- /test/language/test_function_arg_by_ref.zs: -------------------------------------------------------------------------------- 1 | class A{} 2 | class B{} 3 | 4 | var a=10,c=new A(); 5 | 6 | // function WITHOUT ref 7 | function(_a,_c){ 8 | _a=0; 9 | _c=new B(); 10 | }(a,c) 11 | 12 | System::assert(a==10,"a!=10") 13 | System::assert(c instanceof A,"!(c instanceof A)") 14 | 15 | a=10 16 | c=new A(); 17 | 18 | // function WITH ref 19 | function(ref _a, ref _c){ 20 | _a=0; 21 | var b=_c; 22 | _c=new B(); // _c write reg 23 | }(a,c) 24 | 25 | 26 | System::assert(a==0,"a!=0") 27 | System::assert(c instanceof B,"!(c instanceof B)") 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/language/test_function_arg_default.zs: -------------------------------------------------------------------------------- 1 | function f(a,b=0,c){ 2 | 3 | System::assert(b==0,"b!=0"); 4 | System::assert(c==undefined,"c!=undefined"); 5 | } 6 | 7 | f(0) 8 | 9 | -------------------------------------------------------------------------------- /test/language/test_if_else.zs: -------------------------------------------------------------------------------- 1 | 2 | function test_conditional(_n){ 3 | if(_n<10){ 4 | return "_n<10"; 5 | }else if(_n<20){ 6 | return "_n<20"; 7 | }else{ 8 | return "_n>=20"; 9 | } 10 | } 11 | 12 | System::assert(test_conditional(5)=="_n<10","!= _n<10"); 13 | System::assert(test_conditional(15)=="_n<20","!= _n<20"); 14 | System::assert(test_conditional(25)=="_n>=20","!= _n>=20"); 15 | 16 | -------------------------------------------------------------------------------- /test/language/test_import.zs: -------------------------------------------------------------------------------- 1 | import "import/C.zs" 2 | 3 | var c= new C(5); // initializes data2 as 3.0 and return the value 4 | 5 | System::assert(c.a==35,"c.a != 35"); -------------------------------------------------------------------------------- /test/language/test_instance_from_var_type.zs: -------------------------------------------------------------------------------- 1 | class A{ 2 | A(){ 3 | } 4 | } 5 | 6 | // it loads type of A into variable type_a 7 | var type_a=A; 8 | 9 | 10 | // it can create instances from vars that contains a type 11 | new type_a(); 12 | 13 | System::assert(type_a == A,"type_a != typeof A") 14 | 15 | -------------------------------------------------------------------------------- /test/language/test_integer_values.zs: -------------------------------------------------------------------------------- 1 | System::assert(01010101b==85,"01010101b!=85") 2 | System::assert(0xfefe==65278,"0xfefe!=65278") 3 | //System::assert((""+(-2252400000))=="-2252400000","\"-2252400000\"!=\"-2252400000\"") 4 | -------------------------------------------------------------------------------- /test/language/test_iterator_array.zs: -------------------------------------------------------------------------------- 1 | var v1=[1,"string",true] 2 | var r="" 3 | 4 | for(var it=v1._iter();!it._end();it._next()){ 5 | var k,v; 6 | k,v=it._get(); 7 | r+=v 8 | } 9 | 10 | System::assert(r=="1stringtrue","r!=1stringtrue") -------------------------------------------------------------------------------- /test/language/test_iterator_metamethod.zs: -------------------------------------------------------------------------------- 1 | class CustomObjectIterator{ 2 | constructor(_cv){ 3 | this.cv=_cv 4 | this.idx=0 5 | } 6 | 7 | _get(){ 8 | return this.cv.data[this.idx] 9 | } 10 | 11 | _postinc(){ 12 | if(this._end() == false){ 13 | this.idx++; 14 | } 15 | } 16 | 17 | _end(){ 18 | return this.idx==this.cv.data.length 19 | } 20 | } 21 | 22 | class CustomArray{ 23 | var data=[1,2,3,4] 24 | 25 | _iter(){ 26 | return new CustomObjectIterator(this) 27 | } 28 | } 29 | 30 | var data=new CustomArray([1,2,3,4]) 31 | 32 | for(var d in data){ 33 | Console::outln(d) 34 | } -------------------------------------------------------------------------------- /test/language/test_iterator_object.zs: -------------------------------------------------------------------------------- 1 | var o={a:1,b:"string",c:true} 2 | var k,v; 3 | var rk="" 4 | var rv="" 5 | 6 | System::assert(Object::keys(o).length==3,"Object::keys(o).length!=3"); 7 | 8 | for(var it=Object::_iter(o);!it._end();it._next()){ 9 | k,v=it._get(); 10 | rk+=k 11 | rv+=v 12 | } 13 | 14 | System::assert(rk=="abc","rk!=abc") 15 | System::assert(rv=="1stringtrue","rv!=1stringtrue") 16 | 17 | -------------------------------------------------------------------------------- /test/language/test_iterator_string.zs: -------------------------------------------------------------------------------- 1 | var sum_k=0; 2 | var sum_v=0; 3 | var str="abcd" 4 | 5 | for(var it=str._iter();!it._end();it._next()){ 6 | var k,v; 7 | k,v=it._get(); 8 | sum_k+=k; 9 | sum_v+=v; 10 | 11 | } 12 | 13 | System::assert(sum_k==6,"sum_k!=6") 14 | System::assert(sum_v=='a'+'b'+'c'+'d',"sum_v!="+str) 15 | 16 | -------------------------------------------------------------------------------- /test/language/test_lexical_scope.zs: -------------------------------------------------------------------------------- 1 | function generate_function(){ 2 | var i=0; 3 | return function(){ 4 | Console::outln("i:"+i) 5 | i++; 6 | }() 7 | 8 | } 9 | 10 | function(){ 11 | Console::outln("i1") 12 | //i++; 13 | }() 14 | 15 | var f=generate_function(); 16 | 17 | //f(); -------------------------------------------------------------------------------- /test/language/test_loops.zs: -------------------------------------------------------------------------------- 1 | 2 | // for 3 | var k=0; 4 | for(var i=0;i < 10; i++){ 5 | k++; 6 | } 7 | 8 | System::assert(k==10,"1.for k!=10"); 9 | 10 | k=0; 11 | for(k=0;k < 10; k++){ 12 | } 13 | 14 | System::assert(k==10,"2.for k!=10"); 15 | 16 | k=0; 17 | while(k < 10){ 18 | k++; 19 | } 20 | 21 | System::assert(k==10,"3.while k!=10"); 22 | 23 | k=0; 24 | do{ 25 | k++; 26 | }while(k<10); 27 | 28 | System::assert(k==10,"4.do-while k!=10"); -------------------------------------------------------------------------------- /test/language/test_member_function_call_object_on_unallocated_object.zs: -------------------------------------------------------------------------------- 1 | var a=null 2 | 3 | class A{ 4 | constructor(){ 5 | this.b=10 6 | a=this.member_function 7 | a(); 8 | } 9 | 10 | member_function(){ 11 | this.b=100 12 | Console::outln("b:{0}",this.b) 13 | } // creates a member function object and assigns to global var 14 | 15 | 16 | 17 | } 18 | 19 | function createA(){ 20 | new A() 21 | } 22 | 23 | 24 | createA(); 25 | 26 | a(); //<-- cannot called because the object was destroyed -------------------------------------------------------------------------------- /test/language/test_member_variables.zs: -------------------------------------------------------------------------------- 1 | // A class example ... 2 | class A{ 3 | // ... with built-in member vars with optional initialization 4 | var a,b=-1,c=-2 5 | const MAX_NUM=9; 6 | 7 | constructor(a,b=-1,c=A::MAX_NUM){ 8 | this.a=a; // this.a member 9 | this.b=b; // this.b member 10 | this.c=c; // this.c member 11 | this.d=-100; // this.d user property 12 | this["e"]=-200; // another user property usign [] 13 | this.h=this.f; // 14 | } 15 | 16 | }; 17 | 18 | 19 | 20 | // late bind var 21 | var A::f=-1,A::g 22 | 23 | var a=new A(1); 24 | System::assert(a.a==1,"a!=1"); 25 | System::assert(a.b==-1,"a.b!=-1"); 26 | System::assert(a.c==A::MAX_NUM,"a.c!=A::MAX_NUM"); 27 | System::assert(a.d==-100,"a.d!=-100"); 28 | System::assert(a.e==-200,"a.e!=-200"); 29 | System::assert(a.f==-1,"a.f!=-1"); 30 | System::assert(a.g==undefined,"a.g!=undefined"); 31 | System::assert(a.h==-1,"a.h!=-1"); 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/language/test_ternary.zs: -------------------------------------------------------------------------------- 1 | var a=1; 2 | var b; 3 | 4 | var j= 5 | a>0 ? //if(a>0){ 6 | (a>1) ? // if(a>2){ 7 | a+3 // a+3 8 | : b=a > 4 ? // }else if(b=a>4){ // it also assigns the result of ternary into b 9 | a+5 // a+2 5 10 | : // }else{ 11 | a>3? // if(a>3){ 12 | a+4 // a+4 13 | : // }else{ 14 | a+2 // a+2 15 | // } 16 | // } 17 | : //}else{ 18 | a+1 // a+1 19 | //} 20 | // Should be j=3 and b=3 (b=a>4 ? a+5:a>3?a+4:a+2 --> it assigns the result of ternary which is correct. Note is not recommended doing assignations during ternari op ) 21 | System::assert(j==3,"j!=3"); 22 | System::assert(b==3,"b!=3"); 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/language/test_typeof.zs: -------------------------------------------------------------------------------- 1 | class A{} 2 | 3 | System::assert(typeof 0==Integer,"typeof 0 != Integer") 4 | System::assert(typeof 1.0==Float,"typeof 1.0 != Float") 5 | System::assert(typeof true==Boolean,"typeof true != Boolean") 6 | System::assert(typeof "str"==String,"typeof \"str\" != String") 7 | System::assert(typeof [0,1,2]==Array,"typeof [0,1,2] != Array") 8 | System::assert(typeof {a:0,b:1}==Object,"typeof {a:0,b:1} != Object") 9 | System::assert(typeof new A()==A,"typeof new A() != A") 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/test_all_config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is distributed under the MIT License. 3 | * See LICENSE file for details. 4 | */ 5 | #ifndef ZS_TEST_ALL_CONFIG_H 6 | #define ZS_TEST_ALL_CONFIG_H 7 | 8 | #define ZS_TEST_ALL_SCRIPT_TEST_PATH "${ZS_TEST_ALL_SCRIPT_TEST_PATH}" 9 | 10 | #endif /* ZS_TEST_ALL_CONFIG_H */ 11 | 12 | 13 | --------------------------------------------------------------------------------