├── .editorconfig ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── README_zh.md ├── apps └── tuya_cloud │ └── switch_demo │ └── switch_demo.lua ├── components ├── elua │ ├── .gitignore │ ├── doc │ │ └── elua.md │ ├── include │ │ ├── lapi.h │ │ ├── lauxlib.h │ │ ├── lcode.h │ │ ├── lctype.h │ │ ├── ldebug.h │ │ ├── ldo.h │ │ ├── lfunc.h │ │ ├── lgc.h │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmem.h │ │ ├── lobject.h │ │ ├── lopcodes.h │ │ ├── lparser.h │ │ ├── lprefix.h │ │ ├── lstate.h │ │ ├── lstring.h │ │ ├── ltable.h │ │ ├── ltm.h │ │ ├── lua.h │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.h │ │ ├── lvm.h │ │ ├── lzio.h │ │ └── rotable2.h │ ├── plugin │ │ ├── alien │ │ │ ├── Makefile.am │ │ │ ├── Makefile.in │ │ │ ├── Makefile.win │ │ │ ├── Makefile.win64 │ │ │ ├── README │ │ │ ├── aclocal.m4 │ │ │ ├── alien-0.7.1-1.rockspec │ │ │ ├── alien.rockspec.in │ │ │ ├── autom4te.cache │ │ │ │ ├── output.0 │ │ │ │ ├── output.1 │ │ │ │ ├── output.2 │ │ │ │ ├── requests │ │ │ │ ├── traces.0 │ │ │ │ ├── traces.1 │ │ │ │ └── traces.2 │ │ │ ├── bootstrap │ │ │ ├── bootstrap.conf │ │ │ ├── build-aux │ │ │ │ ├── .gitignore │ │ │ │ ├── Makefile.am │ │ │ │ ├── extract-trace │ │ │ │ └── options-parser │ │ │ ├── config.h │ │ │ ├── config.h.in │ │ │ ├── config.log │ │ │ ├── config.status │ │ │ ├── configure │ │ │ ├── configure.ac │ │ │ ├── doc │ │ │ │ ├── .gitignore │ │ │ │ ├── Makefile.am │ │ │ │ └── alien.md │ │ │ ├── libtool │ │ │ ├── m4 │ │ │ │ ├── .gitignore │ │ │ │ └── ax_lua.m4 │ │ │ ├── samples │ │ │ │ ├── Makefile.am │ │ │ │ ├── gtk.lua │ │ │ │ ├── libc.lua │ │ │ │ └── string_array.lua │ │ │ ├── src │ │ │ │ ├── .deps │ │ │ │ │ └── alien.Plo │ │ │ │ ├── .gitignore │ │ │ │ ├── Makefile.am │ │ │ │ ├── alien.c │ │ │ │ ├── alien.def │ │ │ │ ├── alien.lua │ │ │ │ ├── constants │ │ │ │ └── struct.c │ │ │ ├── stamp-h1 │ │ │ └── tests │ │ │ │ ├── .deps │ │ │ │ └── alientest.Plo │ │ │ │ ├── Makefile.am │ │ │ │ ├── alientest.c │ │ │ │ └── test_alien.lua │ │ └── cffi-lua │ │ │ ├── .ci │ │ │ ├── README.md │ │ │ ├── build-cffi │ │ │ ├── build-cffi-windows │ │ │ ├── install-env │ │ │ └── install-env-windows │ │ │ ├── CHANGELOG.md │ │ │ ├── COPYING.md │ │ │ ├── README.md │ │ │ ├── STATUS.md │ │ │ ├── cffi-lua-0.2.3-1.rockspec │ │ │ ├── docs │ │ │ ├── api.md │ │ │ ├── introduction.md │ │ │ ├── semantics.md │ │ │ └── syntax.md │ │ │ ├── luarocks │ │ │ └── build.sh │ │ │ ├── meson.build │ │ │ ├── meson_options.txt │ │ │ ├── src │ │ │ ├── ast.cc │ │ │ ├── ast.hh │ │ │ ├── ffi.cc │ │ │ ├── ffi.hh │ │ │ ├── ffilib.cc │ │ │ ├── lib.cc │ │ │ ├── lib.hh │ │ │ ├── libffi.hh │ │ │ ├── lua.cc │ │ │ ├── lua.hh │ │ │ ├── lua.hpp │ │ │ ├── lua_ffi_module.c │ │ │ ├── main.cc │ │ │ ├── parser.cc │ │ │ ├── parser.hh │ │ │ ├── platform.hh │ │ │ ├── util.cc │ │ │ └── util.hh │ │ │ └── tests │ │ │ ├── abi.lua │ │ │ ├── callbacks.lua │ │ │ ├── callconv.lua │ │ │ ├── cast.lua │ │ │ ├── cexpr.lua │ │ │ ├── copy_fill.lua │ │ │ ├── dump_string.lua │ │ │ ├── globals.lua │ │ │ ├── istype.lua │ │ │ ├── meson.build │ │ │ ├── metatype.lua │ │ │ ├── metatype54.lua │ │ │ ├── parameterized.lua │ │ │ ├── redef.lua │ │ │ ├── redir.lua │ │ │ ├── runner.lua │ │ │ ├── scalar.lua │ │ │ ├── simple.lua │ │ │ ├── simple_pass.lua │ │ │ ├── struct_array.lua │ │ │ ├── struct_pass.lua │ │ │ ├── struct_union_array_fields.lua │ │ │ ├── table_init.lua │ │ │ ├── testlib.cc │ │ │ ├── testlib.lua │ │ │ ├── unionval.lua │ │ │ └── variadic.lua │ └── src │ │ ├── lapi.c │ │ ├── lauxlib.c │ │ ├── lbaselib.c │ │ ├── lbitlib.c │ │ ├── lcode.c │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldo.c │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lgc.c │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lopcodes.c │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lstate.c │ │ ├── lstring.c │ │ ├── lstrlib.c │ │ ├── lstrlib_exts.c │ │ ├── ltable.c │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── lundump.c │ │ ├── lutf8lib.c │ │ ├── lvm.c │ │ ├── lzio.c │ │ └── rotable2.c └── modules │ ├── libffi │ ├── .gitignore │ ├── ChangeLog.old │ ├── LICENSE │ ├── LICENSE-BUILDTOOLS │ ├── Makefile │ ├── Makefile.am │ ├── Makefile.in │ ├── README.md │ ├── acinclude.m4 │ ├── aclocal.m4 │ ├── autogen.sh │ ├── autom4te.cache │ │ ├── output.0 │ │ ├── output.1 │ │ ├── output.2 │ │ ├── output.3 │ │ ├── requests │ │ ├── traces.0 │ │ ├── traces.1 │ │ ├── traces.2 │ │ └── traces.3 │ ├── compile │ ├── config.guess │ ├── config.sub │ ├── configure │ ├── configure.ac │ ├── configure.host │ ├── depcomp │ ├── doc │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── libffi.info │ │ ├── libffi.texi │ │ ├── mdate-sh │ │ ├── texinfo.tex │ │ └── version.texi │ ├── fficonfig.h.in │ ├── generate-darwin-source-and-headers.py │ ├── include │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── ffi.h.in │ │ ├── ffi_cfi.h │ │ ├── ffi_common.h │ │ └── tramp.h │ ├── install-sh │ ├── libffi.map.in │ ├── libffi.pc.in │ ├── libffi.xcodeproj │ │ └── project.pbxproj │ ├── libtool-ldflags │ ├── libtool-version │ ├── local.mk │ ├── ltmain.sh │ ├── m4 │ │ ├── asmcfi.m4 │ │ ├── ax_append_flag.m4 │ │ ├── ax_cc_maxopt.m4 │ │ ├── ax_cflags_warn_all.m4 │ │ ├── ax_check_compile_flag.m4 │ │ ├── ax_compiler_vendor.m4 │ │ ├── ax_configure_args.m4 │ │ ├── ax_enable_builddir.m4 │ │ ├── ax_gcc_archflag.m4 │ │ ├── ax_gcc_x86_cpuid.m4 │ │ ├── ax_prepend_flag.m4 │ │ ├── ax_require_defined.m4 │ │ ├── libtool.m4 │ │ ├── ltoptions.m4 │ │ ├── ltsugar.m4 │ │ ├── ltversion.m4 │ │ └── lt~obsolete.m4 │ ├── make_sunver.pl │ ├── man │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── ffi.3 │ │ ├── ffi_call.3 │ │ ├── ffi_prep_cif.3 │ │ └── ffi_prep_cif_var.3 │ ├── missing │ ├── msvc_build │ │ └── aarch64 │ │ │ ├── Ffi_staticLib.sln │ │ │ ├── Ffi_staticLib.vcxproj │ │ │ ├── Ffi_staticLib.vcxproj.filters │ │ │ ├── Ffi_staticLib.vcxproj.user │ │ │ └── aarch64_include │ │ │ ├── ffi.h │ │ │ └── fficonfig.h │ ├── msvcc.sh │ ├── src │ │ ├── aarch64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ ├── sysv.S │ │ │ └── win64_armasm.S │ │ ├── alpha │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ └── osf.S │ │ ├── arc │ │ │ ├── arcompact.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── arm │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ ├── sysv.S │ │ │ └── sysv_msvc_arm32.S │ │ ├── avr32 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── bfin │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── closures.c │ │ ├── cris │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── csky │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── debug.c │ │ ├── dlmalloc.c │ │ ├── frv │ │ │ ├── eabi.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── ia64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── ia64_flags.h │ │ │ └── unix.S │ │ ├── java_raw_api.c │ │ ├── kvx │ │ │ ├── asm.h │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── loongarch64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── m32r │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── m68k │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── m88k │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── obsd.S │ │ ├── metag │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── microblaze │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── mips │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── n32.S │ │ │ └── o32.S │ │ ├── moxie │ │ │ ├── eabi.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── nios2 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── or1k │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── pa │ │ │ ├── ffi.c │ │ │ ├── ffi64.c │ │ │ ├── ffitarget.h │ │ │ ├── hpux32.S │ │ │ ├── hpux64.S │ │ │ └── linux.S │ │ ├── powerpc │ │ │ ├── aix.S │ │ │ ├── aix_closure.S │ │ │ ├── asm.h │ │ │ ├── darwin.S │ │ │ ├── darwin_closure.S │ │ │ ├── ffi.c │ │ │ ├── ffi_darwin.c │ │ │ ├── ffi_linux64.c │ │ │ ├── ffi_powerpc.h │ │ │ ├── ffi_sysv.c │ │ │ ├── ffitarget.h │ │ │ ├── linux64.S │ │ │ ├── linux64_closure.S │ │ │ ├── ppc_closure.S │ │ │ ├── sysv.S │ │ │ └── t-aix │ │ ├── prep_cif.c │ │ ├── raw_api.c │ │ ├── riscv │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── s390 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ └── sysv.S │ │ ├── sh │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── sh64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── sparc │ │ │ ├── ffi.c │ │ │ ├── ffi64.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ ├── v8.S │ │ │ └── v9.S │ │ ├── tile │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── tile.S │ │ ├── tramp.c │ │ ├── types.c │ │ ├── vax │ │ │ ├── elfbsd.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── wasm32 │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── x86 │ │ │ ├── asmnames.h │ │ │ ├── ffi.c │ │ │ ├── ffi64.c │ │ │ ├── ffitarget.h │ │ │ ├── ffiw64.c │ │ │ ├── internal.h │ │ │ ├── internal64.h │ │ │ ├── sysv.S │ │ │ ├── sysv_intel.S │ │ │ ├── unix64.S │ │ │ ├── win64.S │ │ │ └── win64_intel.S │ │ └── xtensa │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ ├── stamp-h.in │ └── testsuite │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── config │ │ └── default.exp │ │ ├── emscripten │ │ ├── build-tests.sh │ │ ├── build.sh │ │ ├── conftest.py │ │ ├── node-tests.sh │ │ ├── test.html │ │ └── test_libffi.py │ │ ├── lib │ │ ├── libffi.exp │ │ ├── target-libpath.exp │ │ └── wrapper.exp │ │ ├── libffi.bhaible │ │ ├── Makefile │ │ ├── README │ │ ├── alignof.h │ │ ├── bhaible.exp │ │ ├── test-call.c │ │ ├── test-callback.c │ │ └── testcases.c │ │ ├── libffi.call │ │ ├── align_mixed.c │ │ ├── align_stdcall.c │ │ ├── bpo_38748.c │ │ ├── call.exp │ │ ├── callback.c │ │ ├── callback2.c │ │ ├── callback3.c │ │ ├── callback4.c │ │ ├── err_bad_typedef.c │ │ ├── ffitest.h │ │ ├── float.c │ │ ├── float1.c │ │ ├── float2.c │ │ ├── float3.c │ │ ├── float4.c │ │ ├── float_va.c │ │ ├── many.c │ │ ├── many2.c │ │ ├── many_double.c │ │ ├── many_mixed.c │ │ ├── negint.c │ │ ├── offsets.c │ │ ├── pr1172638.c │ │ ├── promotion.c │ │ ├── pyobjc_tc.c │ │ ├── return_dbl.c │ │ ├── return_dbl1.c │ │ ├── return_dbl2.c │ │ ├── return_fl.c │ │ ├── return_fl1.c │ │ ├── return_fl2.c │ │ ├── return_fl3.c │ │ ├── return_ldl.c │ │ ├── return_ll.c │ │ ├── return_ll1.c │ │ ├── return_sc.c │ │ ├── return_sl.c │ │ ├── return_uc.c │ │ ├── return_ul.c │ │ ├── s55.c │ │ ├── strlen.c │ │ ├── strlen2.c │ │ ├── strlen3.c │ │ ├── strlen4.c │ │ ├── struct1.c │ │ ├── struct10.c │ │ ├── struct2.c │ │ ├── struct3.c │ │ ├── struct4.c │ │ ├── struct5.c │ │ ├── struct6.c │ │ ├── struct7.c │ │ ├── struct8.c │ │ ├── struct9.c │ │ ├── struct_by_value_2.c │ │ ├── struct_by_value_3.c │ │ ├── struct_by_value_3f.c │ │ ├── struct_by_value_4.c │ │ ├── struct_by_value_4f.c │ │ ├── struct_by_value_big.c │ │ ├── struct_by_value_small.c │ │ ├── struct_return_2H.c │ │ ├── struct_return_8H.c │ │ ├── uninitialized.c │ │ ├── va_1.c │ │ ├── va_2.c │ │ ├── va_3.c │ │ ├── va_struct1.c │ │ ├── va_struct2.c │ │ └── va_struct3.c │ │ ├── libffi.closures │ │ ├── closure.exp │ │ ├── closure_fn0.c │ │ ├── closure_fn1.c │ │ ├── closure_fn2.c │ │ ├── closure_fn3.c │ │ ├── closure_fn4.c │ │ ├── closure_fn5.c │ │ ├── closure_fn6.c │ │ ├── closure_loc_fn0.c │ │ ├── closure_simple.c │ │ ├── cls_12byte.c │ │ ├── cls_16byte.c │ │ ├── cls_18byte.c │ │ ├── cls_19byte.c │ │ ├── cls_1_1byte.c │ │ ├── cls_20byte.c │ │ ├── cls_20byte1.c │ │ ├── cls_24byte.c │ │ ├── cls_2byte.c │ │ ├── cls_3_1byte.c │ │ ├── cls_3byte1.c │ │ ├── cls_3byte2.c │ │ ├── cls_3float.c │ │ ├── cls_4_1byte.c │ │ ├── cls_4byte.c │ │ ├── cls_5_1_byte.c │ │ ├── cls_5byte.c │ │ ├── cls_64byte.c │ │ ├── cls_6_1_byte.c │ │ ├── cls_6byte.c │ │ ├── cls_7_1_byte.c │ │ ├── cls_7byte.c │ │ ├── cls_8byte.c │ │ ├── cls_9byte1.c │ │ ├── cls_9byte2.c │ │ ├── cls_align_double.c │ │ ├── cls_align_float.c │ │ ├── cls_align_longdouble.c │ │ ├── cls_align_longdouble_split.c │ │ ├── cls_align_longdouble_split2.c │ │ ├── cls_align_pointer.c │ │ ├── cls_align_sint16.c │ │ ├── cls_align_sint32.c │ │ ├── cls_align_sint64.c │ │ ├── cls_align_uint16.c │ │ ├── cls_align_uint32.c │ │ ├── cls_align_uint64.c │ │ ├── cls_dbls_struct.c │ │ ├── cls_double.c │ │ ├── cls_double_va.c │ │ ├── cls_float.c │ │ ├── cls_longdouble.c │ │ ├── cls_longdouble_va.c │ │ ├── cls_many_mixed_args.c │ │ ├── cls_many_mixed_float_double.c │ │ ├── cls_multi_schar.c │ │ ├── cls_multi_sshort.c │ │ ├── cls_multi_sshortchar.c │ │ ├── cls_multi_uchar.c │ │ ├── cls_multi_ushort.c │ │ ├── cls_multi_ushortchar.c │ │ ├── cls_pointer.c │ │ ├── cls_pointer_stack.c │ │ ├── cls_schar.c │ │ ├── cls_sint.c │ │ ├── cls_sshort.c │ │ ├── cls_struct_va1.c │ │ ├── cls_uchar.c │ │ ├── cls_uint.c │ │ ├── cls_uint_va.c │ │ ├── cls_ulong_va.c │ │ ├── cls_ulonglong.c │ │ ├── cls_ushort.c │ │ ├── err_bad_abi.c │ │ ├── ffitest.h │ │ ├── huge_struct.c │ │ ├── nested_struct.c │ │ ├── nested_struct1.c │ │ ├── nested_struct10.c │ │ ├── nested_struct11.c │ │ ├── nested_struct12.c │ │ ├── nested_struct13.c │ │ ├── nested_struct2.c │ │ ├── nested_struct3.c │ │ ├── nested_struct4.c │ │ ├── nested_struct5.c │ │ ├── nested_struct6.c │ │ ├── nested_struct7.c │ │ ├── nested_struct8.c │ │ ├── nested_struct9.c │ │ ├── problem1.c │ │ ├── single_entry_structs1.c │ │ ├── single_entry_structs2.c │ │ ├── single_entry_structs3.c │ │ ├── stret_large.c │ │ ├── stret_large2.c │ │ ├── stret_medium.c │ │ ├── stret_medium2.c │ │ ├── testclosure.c │ │ ├── unwindtest.cc │ │ └── unwindtest_ffi_call.cc │ │ ├── libffi.complex │ │ ├── cls_align_complex.inc │ │ ├── cls_align_complex_double.c │ │ ├── cls_align_complex_float.c │ │ ├── cls_align_complex_longdouble.c │ │ ├── cls_complex.inc │ │ ├── cls_complex_double.c │ │ ├── cls_complex_float.c │ │ ├── cls_complex_longdouble.c │ │ ├── cls_complex_struct.inc │ │ ├── cls_complex_struct_double.c │ │ ├── cls_complex_struct_float.c │ │ ├── cls_complex_struct_longdouble.c │ │ ├── cls_complex_va.inc │ │ ├── cls_complex_va_double.c │ │ ├── cls_complex_va_float.c │ │ ├── cls_complex_va_longdouble.c │ │ ├── complex.exp │ │ ├── complex.inc │ │ ├── complex_defs_double.inc │ │ ├── complex_defs_float.inc │ │ ├── complex_defs_longdouble.inc │ │ ├── complex_double.c │ │ ├── complex_float.c │ │ ├── complex_int.c │ │ ├── complex_longdouble.c │ │ ├── ffitest.h │ │ ├── many_complex.inc │ │ ├── many_complex_double.c │ │ ├── many_complex_float.c │ │ ├── many_complex_longdouble.c │ │ ├── return_complex.inc │ │ ├── return_complex1.inc │ │ ├── return_complex1_double.c │ │ ├── return_complex1_float.c │ │ ├── return_complex1_longdouble.c │ │ ├── return_complex2.inc │ │ ├── return_complex2_double.c │ │ ├── return_complex2_float.c │ │ ├── return_complex2_longdouble.c │ │ ├── return_complex_double.c │ │ ├── return_complex_float.c │ │ └── return_complex_longdouble.c │ │ └── libffi.go │ │ ├── aa-direct.c │ │ ├── closure1.c │ │ ├── ffitest.h │ │ ├── go.exp │ │ └── static-chain.h │ ├── lua-cjson │ ├── CMakeLists.txt │ ├── LICENSE │ ├── fpconv.c │ ├── fpconv.h │ ├── lua_cjson.c │ ├── strbuf.c │ └── strbuf.h │ ├── lua-mbedtls │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ ├── VERSION │ ├── doc │ │ ├── base64.md │ │ ├── md.md │ │ └── ssl.md │ ├── rockspec │ │ └── lua-mbedtls-git-1.rockspec │ ├── src │ │ ├── base64.c │ │ ├── common.h │ │ ├── defcert.h │ │ ├── https.lua │ │ ├── mbedtls.c │ │ ├── md.c │ │ ├── ssl.c │ │ └── tls.lua │ └── test │ │ └── test-mbedtls.lua │ ├── lua-mqttc │ ├── doc │ │ └── luamqttc.md │ ├── include │ │ └── lua-mqttc.h │ └── src │ │ ├── lua-mqttc-app.c │ │ └── lua-mqttc-client.c │ ├── lua-proc │ ├── lpsched.c │ ├── lpsched.h │ ├── luaproc.c │ └── luaproc.h │ ├── lua-socket │ ├── .editorconfig │ ├── .gitignore │ ├── .luacheckrc │ ├── CHANGELOG.md │ ├── FIX │ ├── LICENSE │ ├── Lua.props │ ├── README.md │ ├── TODO │ ├── WISH │ ├── docs │ │ ├── dns.html │ │ ├── ftp.html │ │ ├── http.html │ │ ├── index.html │ │ ├── installation.html │ │ ├── introduction.html │ │ ├── ltn12.html │ │ ├── lua05.ppt │ │ ├── luasocket.png │ │ ├── mime.html │ │ ├── reference.css │ │ ├── reference.html │ │ ├── smtp.html │ │ ├── socket.html │ │ ├── tcp.html │ │ ├── udp.html │ │ └── url.html │ ├── etc │ │ ├── README │ │ ├── b64.lua │ │ ├── check-links.lua │ │ ├── check-memory.lua │ │ ├── cookie.lua │ │ ├── dict.lua │ │ ├── dispatch.lua │ │ ├── eol.lua │ │ ├── forward.lua │ │ ├── get.lua │ │ ├── links │ │ ├── lp.lua │ │ ├── qp.lua │ │ └── tftp.lua │ ├── gem │ │ ├── ex1.lua │ │ ├── ex10.lua │ │ ├── ex11.lua │ │ ├── ex12.lua │ │ ├── ex2.lua │ │ ├── ex3.lua │ │ ├── ex4.lua │ │ ├── ex5.lua │ │ ├── ex6.lua │ │ ├── ex7.lua │ │ ├── ex8.lua │ │ ├── ex9.lua │ │ ├── gem.c │ │ ├── gt.b64 │ │ ├── input.bin │ │ ├── ltn012.tex │ │ ├── luasocket.png │ │ ├── makefile │ │ ├── myps2pdf │ │ ├── t1.lua │ │ ├── t1lf.txt │ │ ├── t2.lua │ │ ├── t2.txt │ │ ├── t2gt.qp │ │ ├── t3.lua │ │ ├── t4.lua │ │ ├── t5.lua │ │ └── test.lua │ ├── linux.cmd │ ├── logo.ps │ ├── ltn012.wiki │ ├── ltn013.wiki │ ├── luasocket-scm-3.rockspec │ ├── luasocket.sln │ ├── macosx.cmd │ ├── makefile │ ├── makefile.dist │ ├── mime.vcxproj │ ├── mingw.cmd │ ├── rockspecs │ │ ├── luasocket-3.0.0-1.rockspec │ │ ├── luasocket-3.0rc1-2.rockspec │ │ └── luasocket-3.1.0-1.rockspec │ ├── samples │ │ ├── README │ │ ├── cddb.lua │ │ ├── daytimeclnt.lua │ │ ├── echoclnt.lua │ │ ├── echosrvr.lua │ │ ├── listener.lua │ │ ├── lpr.lua │ │ ├── mclisten.lua │ │ ├── mcsend.lua │ │ ├── talker.lua │ │ └── tinyirc.lua │ ├── socket.vcxproj │ ├── src │ │ ├── auxiliar.c │ │ ├── auxiliar.h │ │ ├── buffer.c │ │ ├── buffer.h │ │ ├── compat.c │ │ ├── compat.h │ │ ├── except.c │ │ ├── except.h │ │ ├── ftp.lua │ │ ├── headers.lua │ │ ├── http.lua │ │ ├── inet.c │ │ ├── inet.h │ │ ├── io.c │ │ ├── io.h │ │ ├── ltn12.lua │ │ ├── luasocket.c │ │ ├── luasocket.h │ │ ├── makefile │ │ ├── mbox.lua │ │ ├── mime.c │ │ ├── mime.h │ │ ├── mime.lua │ │ ├── options.c │ │ ├── options.h │ │ ├── pierror.h │ │ ├── select.c │ │ ├── select.h │ │ ├── serial.c │ │ ├── smtp.lua │ │ ├── socket.h │ │ ├── socket.lua │ │ ├── tcp.c │ │ ├── tcp.h │ │ ├── timeout.c │ │ ├── timeout.h │ │ ├── tp.lua │ │ ├── udp.c │ │ ├── udp.h │ │ ├── unix.c │ │ ├── unix.h │ │ ├── unixdgram.c │ │ ├── unixdgram.h │ │ ├── unixstream.c │ │ ├── unixstream.h │ │ ├── url.lua │ │ ├── usocket.c │ │ ├── usocket.h │ │ ├── wsocket.c │ │ └── wsocket.h │ ├── test │ │ ├── README │ │ ├── auth │ │ │ ├── .htaccess │ │ │ ├── .htpasswd │ │ │ └── index.html │ │ ├── cgi │ │ │ ├── cat │ │ │ ├── cat-index-html │ │ │ ├── env │ │ │ ├── query-string │ │ │ ├── redirect-loop │ │ │ └── request-uri │ │ ├── dicttest.lua │ │ ├── excepttest.lua │ │ ├── find-connect-limit │ │ ├── ftptest.lua │ │ ├── hello.lua │ │ ├── httptest.lua │ │ ├── index.html │ │ ├── ltn12test.lua │ │ ├── luasocket.png │ │ ├── mimetest.lua │ │ ├── smtptest.lua │ │ ├── stufftest.lua │ │ ├── tcp-getoptions │ │ ├── test_bind.lua │ │ ├── test_getaddrinfo.lua │ │ ├── test_socket_error.lua │ │ ├── testclnt.lua │ │ ├── testmesg.lua │ │ ├── testsrvr.lua │ │ ├── testsupport.lua │ │ ├── tftptest.lua │ │ ├── udp-zero-length-send │ │ ├── udp-zero-length-send-recv │ │ ├── udpconnectclnt.lua │ │ ├── udpconnectsrvr.lua │ │ ├── unixdgramclnt.lua │ │ ├── unixdgramsrvr.lua │ │ ├── unixstreamclnt.lua │ │ ├── unixstreamsrvr.lua │ │ ├── upload.html │ │ ├── urltest.lua │ │ ├── utestclnt.lua │ │ └── utestsrvr.lua │ ├── vc32.bat │ ├── vc64.bat │ ├── win32.cmd │ └── win64.cmd │ └── lua-tuyaopen │ ├── include │ ├── crc.h │ ├── lua_bsp_config.h │ ├── lua_c_api.h │ ├── lua_main.h │ ├── lua_msgbus.h │ ├── lua_timer.h │ ├── lua_zbuff.h │ └── tuya_config.h │ └── src │ ├── crc.c │ ├── lua_base.c │ ├── lua_c_api.c │ ├── lua_conn.c │ ├── lua_crypto.c │ ├── lua_event.c │ ├── lua_gpio.c │ ├── lua_kvdb.c │ ├── lua_main.c │ ├── lua_modbus.c │ ├── lua_msgbus.c │ ├── lua_ringbuff.c │ ├── lua_system.c │ ├── lua_timer.c │ ├── lua_tuyaos.c │ ├── lua_uart.c │ └── lua_zbuff.c ├── lua_samples ├── base │ └── base.lua ├── file │ ├── file.lua │ ├── file_read.lua │ ├── file_remove.lua │ └── file_write.lua ├── gpio │ ├── gpio_in.lua │ ├── gpio_intr.lua │ ├── gpio_out.lua │ └── led_blink.lua ├── http │ ├── file_download.lua │ ├── file_upload.lua │ ├── http.lua │ └── https.lua ├── mqtt │ ├── broker.emqx.io.ca.crt │ └── mqtt.lua ├── net │ ├── net_connection.lua │ ├── net_tcp_client.lua │ ├── net_tcp_server.lua │ ├── net_udp_client.lua │ ├── net_udp_server.lua │ ├── wifi_ap.lua │ └── wifi_sta.lua ├── system │ ├── system.lua │ └── timer.lua ├── thread │ ├── thread_file.lua │ ├── thread_function.lua │ ├── thread_function_once.lua │ └── thread_string.lua ├── timer │ └── timer_callback.lua ├── uart │ └── uart.lua └── utils │ └── utils.lua ├── main ├── CMakeLists.txt ├── README.md ├── project_build.ini └── src │ ├── main.c │ ├── uart_handler.c │ └── uart_handler.h └── tools └── nodemcu-uploader ├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── doc ├── DEVELOP.md ├── USAGE.md └── bash_completion.d │ └── nodemcu_uploader ├── nodemcu-uploader.py ├── nodemcu_uploader ├── __init__.py ├── __main__.py ├── exceptions.py ├── luacode.py ├── main.py ├── serialutils.py ├── term.py ├── uploader.py ├── utils.py ├── validate.py └── version.py ├── pylintrc ├── setup.cfg ├── setup.py ├── test_requirements.txt ├── tests ├── __init__.py ├── fixtures │ ├── big_file.txt │ ├── led_blink.lua │ ├── medium_file.txt │ ├── riazzerawifi.lua │ ├── signatur.tif │ ├── small_file.txt │ ├── testuploadfail.txt │ └── webserver.lua ├── misc.py ├── torture.py └── uploader.py └── tox.ini /.editorconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/.editorconfig -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | main/.build/ 2 | tuyadb/ 3 | .vscode/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tuyaopen"] 2 | path = tuyaopen 3 | url = https://github.com/tuya/tuyaopen 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Tuya.inc 2024 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | Apache License 8 | Version 2.0, January 2004 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. -------------------------------------------------------------------------------- /components/elua/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | build/ 3 | plugin/alie/src/ 4 | plugin/alie/*.o 5 | plugin/alie/*.lo 6 | plugin/alie/*.la 7 | plugin/alie/*.tar.gz 8 | plugin/alie/*.zip 9 | plugin/alie/*~ 10 | plugin/alie/.deps 11 | plugin/alie/.libs 12 | plugin/alie/.dirstamp 13 | plugin/alie/Makefile.in 14 | plugin/alie/Makefile 15 | plugin/alie//aclocal.m4 16 | plugin/alie//autom4te.cache 17 | plugin/alie//config.h 18 | plugin/alie//config.h.in 19 | plugin/alie//config.log 20 | plugin/alie//config.lt 21 | plugin/alie//config.status 22 | plugin/alie//configure 23 | plugin/alie//libtool 24 | plugin/alie//stamp-h1 25 | plugin/alie//alien*.rockspec 26 | plugin/alie//pulgin/cffi-lua/build 27 | -------------------------------------------------------------------------------- /components/elua/include/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | LUA_API void lua_setmutex(lua_State *L,void *mutex,void (*lock)(void*),void (*unlock)); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /components/elua/include/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /components/elua/include/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | 5 | AM_CPPFLAGS = $(LUA_INCLUDE) 6 | AM_CFLAGS = $(CFLAGS_STACK) 7 | 8 | dist_bin_SCRIPTS = 9 | check_LTLIBRARIES = 10 | dist_data_DATA = 11 | dist_doc_DATA = 12 | lib_LTLIBRARIES = 13 | EXTRA_DIST = $(PACKAGE).rockspec.in $(PACKAGE)-$(VERSION)-1.rockspec 14 | 15 | include build-aux/Makefile.am 16 | include doc/Makefile.am 17 | include samples/Makefile.am 18 | include src/Makefile.am 19 | include tests/Makefile.am 20 | 21 | release: all 22 | git diff --exit-code && \ 23 | git tag -a -m "Release tag" "v$(VERSION)" && \ 24 | git push && git push --tags && \ 25 | $(LUAROCKS) build $(ROCKSPEC) && \ 26 | $(LUAROCKS) upload $(ROCKSPEC) 27 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/alien-0.7.1-1.rockspec: -------------------------------------------------------------------------------- 1 | package="alien" 2 | version="0.7.1-1" 3 | source = { 4 | url = "git://github.com/mascarenhas/alien.git", 5 | branch = "v0.7.1" 6 | } 7 | description = { 8 | summary = "Lua->C FFI", 9 | detailed = [[ 10 | Alien lets a Lua application call load dynamic libraries and call C functions 11 | in a portable way, using libffi. 12 | ]], 13 | license = "MIT/X11", 14 | homepage = "http://mascarenhas.github.com/alien" 15 | } 16 | dependencies = { 17 | "lua >= 5.1" 18 | } 19 | external_dependencies = { 20 | FFI = { library = "ffi" } 21 | } 22 | build = { 23 | type = "command", 24 | build_command = "./configure LUA=$(LUA) CPPFLAGS='-I$(LUA_INCDIR) -I$(FFI_INCDIR)' LDFLAGS=-L$(FFI_LIBDIR) --prefix=$(PREFIX) --libdir=$(LIBDIR) --datadir=$(LUADIR) && make clean && make", 25 | install_command = "make install", 26 | copy_directories = {} 27 | } 28 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/alien.rockspec.in: -------------------------------------------------------------------------------- 1 | package="@PACKAGE@" 2 | version="@VERSION@-1" 3 | source = { 4 | url = "git://github.com/mascarenhas/@PACKAGE@.git", 5 | branch = "v@VERSION@" 6 | } 7 | description = { 8 | summary = "Lua->C FFI", 9 | detailed = [[ 10 | Alien lets a Lua application call load dynamic libraries and call C functions 11 | in a portable way, using libffi. 12 | ]], 13 | license = "MIT/X11", 14 | homepage = "http://mascarenhas.github.com/alien" 15 | } 16 | dependencies = { 17 | "lua >= 5.1" 18 | } 19 | external_dependencies = { 20 | FFI = { library = "ffi" } 21 | } 22 | build = { 23 | type = "command", 24 | build_command = "./configure LUA=$(LUA) CPPFLAGS='-I$(LUA_INCDIR) -I$(FFI_INCDIR)' LDFLAGS=-L$(FFI_LIBDIR) --prefix=$(PREFIX) --libdir=$(LIBDIR) --datadir=$(LUADIR) && make clean && make", 25 | install_command = "make install", 26 | copy_directories = {} 27 | } 28 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/build-aux/.gitignore: -------------------------------------------------------------------------------- 1 | /ar-lib 2 | /compile 3 | /config.guess 4 | /config.sub 5 | /depcomp 6 | /install-sh 7 | /ltmain.sh 8 | /missing 9 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/build-aux/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST += \ 2 | build-aux/extract-trace \ 3 | build-aux/options-parser 4 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/doc/.gitignore: -------------------------------------------------------------------------------- 1 | alien.html 2 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/doc/Makefile.am: -------------------------------------------------------------------------------- 1 | dist_doc_DATA += doc/alien.html 2 | dist_doc_DATA += doc/alien.md 3 | 4 | doc/alien.html: $(srcdir)/doc/alien.md 5 | markdown $< > $@ 6 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /ltoptions.m4 3 | /ltsugar.m4 4 | /ltversion.m4 5 | /lt~obsolete.m4 6 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/samples/Makefile.am: -------------------------------------------------------------------------------- 1 | samplesdir = $(docdir)/samples 2 | dist_samples_DATA = $(srcdir)/samples/*.lua 3 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/samples/gtk.lua: -------------------------------------------------------------------------------- 1 | require "luarocks.require" 2 | require "alien" 3 | 4 | local gtk,p,i=alien.load("/usr/lib/libgtk-x11-2.0.so.0"),"pointer","int" 5 | 6 | gtk.gtk_init:types(nil,p,p) 7 | gtk.gtk_message_dialog_new:types(p,p,i,i,i,p) 8 | gtk.gtk_dialog_run:types(i,p) 9 | 10 | gtk.gtk_init(nil,nil) 11 | gtk.gtk_dialog_run(gtk.gtk_message_dialog_new(nil,0,0,1,"Alien Rocks!")) 12 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/samples/libc.lua: -------------------------------------------------------------------------------- 1 | 2 | require "alien" 3 | 4 | local libc = alien.default 5 | 6 | libc.malloc:types("pointer", "int") 7 | libc.free:types("void", "pointer") 8 | libc.strcpy:types("void", "pointer", "string") 9 | libc.strcat:types("void", "pointer", "string") 10 | libc.puts:types("void", "string") 11 | 12 | local foo = libc.malloc(string.len("foo") + string.len("bar") + 1) 13 | libc.strcpy(foo, "foo") 14 | libc.strcat(foo, "bar") 15 | libc.puts(foo) 16 | libc.strcpy(foo, "bar") 17 | libc.puts(foo) 18 | libc.puts("Yeah!") 19 | libc.free(foo) 20 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/samples/string_array.lua: -------------------------------------------------------------------------------- 1 | require "luarocks.require" 2 | require "alien" 3 | 4 | local glib = alien.load("/usr/lib/libglib-2.0.so.0") 5 | local v,p,i,s = "void","pointer","int","string" 6 | 7 | glib.g_strsplit:types(p,s,s,i) -- string to array 8 | glib.g_strjoinv:types(s,s,p) -- array to string 9 | glib.g_strv_length:types(i,p) -- length of array 10 | glib.g_strfreev:types(v,p) -- free array 11 | 12 | 13 | local delim = "\n" 14 | 15 | local strings = {"foo", "bar", "baz"} 16 | 17 | local lines=table.concat(strings, delim) 18 | local strv=glib.g_strsplit(lines,delim,0) 19 | print("length:", glib.g_strv_length(strv)) 20 | 21 | local result=glib.g_strjoinv(delim,strv) 22 | 23 | glib.g_strfreev(strv); 24 | 25 | print(result) 26 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/src/.deps/alien.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/src/.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/src/Makefile.am: -------------------------------------------------------------------------------- 1 | dist_data_DATA += src/alien.lua 2 | dist_bin_SCRIPTS += $(srcdir)/src/constants 3 | 4 | lib_LTLIBRARIES += src/alien_c.la 5 | 6 | src_alien_c_la_SOURCES = src/alien.c 7 | src_alien_c_la_LDFLAGS = -module -avoid-version -lffi 8 | 9 | # This file is #included, so does not need to be compiled 10 | EXTRA_DIST += src/struct.c 11 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/src/alien.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | luaopen_alien_c 3 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/src/constants: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | -- Generates a .c file that outputs a Lua script with C constants 4 | 5 | local const_file = select(1, ...) 6 | local c_file = select(2, ...) 7 | local lua_file = select(3, ...) 8 | 9 | if not const_file or not c_file or not lua_file then 10 | print("Syntax: lua constants.lua ") 11 | os.exit(1) 12 | end 13 | 14 | c_file = io.open(c_file, "w+") 15 | 16 | local prologue = true 17 | 18 | c_file:write[[ 19 | /* Generated by Alien constants */ 20 | 21 | #include 22 | 23 | ]] 24 | 25 | for line in io.lines(const_file) do 26 | if line:match("^%s*#") then 27 | c_file:write(line .. '\n') 28 | elseif not line:match("^%s*$") then 29 | if prologue then 30 | prologue = false 31 | c_file:write('#define LUA_FILE "' .. lua_file .. '"\n') 32 | c_file:write[[ 33 | int main() { 34 | FILE *f = fopen(LUA_FILE, "w+"); 35 | fprintf(f, "-- Generated by Alien constants\n\n"); 36 | ]] 37 | end 38 | local var, val = line:match("^([^=]+)=(.+)$") 39 | if not var then 40 | var, val = line, line 41 | end 42 | c_file:write([[ 43 | fprintf(f, "%s = %i\n", "]] .. var .. [[", ]] .. val .. [[); 44 | ]]) 45 | end 46 | end 47 | 48 | c_file:write[[ 49 | fclose(f); 50 | } 51 | ]] 52 | 53 | c_file:close() 54 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/tests/.deps/alientest.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /components/elua/plugin/alien/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | LUA_PATH ?= ; 2 | LUA_CPATH ?= ; 3 | LUA_ENV = LUA_INIT= LUA_PATH="$(abs_srcdir)/src/?.lua;$(LUA_PATH)" LUA_CPATH="$(abs_builddir)/src/?$(shrext);$(LUA_CPATH)" LD_LIBRARY_PATH="$(abs_builddir)/tests/$(objdir)" 4 | 5 | check_LTLIBRARIES += tests/libalientest.la 6 | 7 | EXTRA_DIST += $(srcdir)/tests/test_alien.lua 8 | 9 | tests_libalientest_la_SOURCES = tests/alientest.c 10 | # -rpath ensures that the .so is built by "make check" 11 | tests_libalientest_la_LDFLAGS = -module -avoid-version -rpath /dev/null 12 | 13 | check-local: 14 | cp src/$(objdir)/alien_c$(shrext) src/ 15 | cd tests && $(LUA_ENV) $(LUA) $(abs_srcdir)/tests/test_alien.lua 16 | rm -f src/alien_c$(shrext) 17 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/.ci/README.md: -------------------------------------------------------------------------------- 1 | # cffi-lua CI scripts 2 | 3 | These CI scripts are meant to provide a helper environment for continuous 4 | integration. They are written to be used only in the CI environment, not 5 | general purpose environments. 6 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/.ci/build-cffi-windows: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | unset CC CXX CC_FOR_BUILD CXX_FOR_BUILD 4 | 5 | export PATH="$(pwd)/host_tools:$PATH" 6 | 7 | echo ">> Setting up lua..." 8 | 9 | for luaver in ${LUA_VERSIONS}; do 10 | mv lua-${luaver} deps-${luaver} || exit 1 11 | done 12 | 13 | echo ">> Building and testing cffi..." 14 | 15 | args="" 16 | if [ -n "$BUILDTYPE" ]; then 17 | args="${args} --buildtype=$BUILDTYPE" 18 | fi 19 | 20 | for luaver in ${LUA_VERSIONS}; do 21 | mkdir -p build-${luaver} 22 | cd build-${luaver} 23 | 24 | cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat' amd64 '&&' \ 25 | meson .. -Dlua_version=vendor -Ddeps_dir=deps-${luaver} ${args} '&&' \ 26 | ninja all '&&' ninja test || exit 1 27 | 28 | cd .. 29 | done 30 | 31 | exit 0 32 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/.ci/install-env-windows: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ninja_version=1.10.2 4 | 5 | echo ">> Installing meson..." 6 | 7 | mkdir -p host_tools 8 | 9 | curl -L -o ninja.zip https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-win.zip || exit 1 10 | 7z x ninja.zip || exit 1 11 | mv ninja.exe host_tools 12 | 13 | pip3 install meson 14 | 15 | echo ">> Getting lua..." 16 | 17 | lua_build="Win64_dll16_lib" 18 | lua_bin="Win64_bin" 19 | 20 | for luaver in ${LUA_VERSIONS}; do 21 | lua_dmaj=${luaver:0:3} 22 | lua_maj=${lua_dmaj/./} 23 | # lua from luabinaries 24 | curl -L -o lua-${luaver}-bin.zip https://downloads.sourceforge.net/project/luabinaries/${luaver}/Tools%20Executables/lua-${luaver}_${lua_bin}.zip || exit 1 25 | curl -L -o lua-${luaver}-lib.zip https://downloads.sourceforge.net/project/luabinaries/${luaver}/Windows%20Libraries/Dynamic/lua-${luaver}_${lua_build}.zip || exit 1 26 | mkdir lua-${luaver} 27 | cd lua-${luaver} 28 | # unzip bin first 29 | 7z x ../lua-${luaver}-bin.zip || exit 1 30 | 7z x ../lua-${luaver}-lib.zip -y || exit 1 31 | cd .. 32 | done 33 | 34 | exit 0 35 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/COPYING.md: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | 3 | Copyright (c) 2020 Daniel "q66" Kolesa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/luarocks/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | # luarocks more like luasucks 6 | case "$CC" in 7 | *-cc) export CXX=${CC/-cc/-c++} ;; 8 | cc) export CXX=c++ ;; 9 | *-gcc) export CXX=${CC/-gcc/-g++} ;; 10 | gcc) export CXX=g++ ;; 11 | *clang*) export CXX=${CC/clang/clang++} ;; 12 | *) export CXX=$CC ;; 13 | esac 14 | 15 | # should be okay 16 | export CXXFLAGS="$CFLAGS" 17 | 18 | case "$1" in 19 | build) 20 | rm -rf build && mkdir build && cd build 21 | meson .. -Dbuildtype=release -Dlua_version=custom \ 22 | -Dtests=false -Dlua_install_path="$LIBDIR" \ 23 | --force-fallback-for=libffi 24 | ninja all 25 | ;; 26 | install) 27 | # we want just the module, no subproject stuff 28 | mkdir -p "$LIBDIR" 29 | cp build/cffi.so "$LIBDIR" 30 | mkdir -p "${PREFIX}"/doc 31 | cp -a docs/* "${PREFIX}"/doc 32 | rm -rf build 33 | ;; 34 | *) exit 1 ;; 35 | esac 36 | 37 | exit 0 38 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/src/lib.hh: -------------------------------------------------------------------------------- 1 | #ifndef LIB_HH 2 | #define LIB_HH 3 | 4 | #include "lua.hh" 5 | 6 | namespace lib { 7 | 8 | using handle = void *; 9 | using func = void (*)(); 10 | 11 | struct c_lib { 12 | handle h; 13 | int cache; 14 | }; 15 | 16 | void load(c_lib *cl, char const *path, lua_State *L, bool global = false); 17 | 18 | void close(c_lib *cl, lua_State *L); 19 | 20 | void *get_sym(c_lib const *cl, lua_State *L, char const *name); 21 | 22 | bool is_c(c_lib const *cl); 23 | 24 | } /* namespace lib */ 25 | 26 | #endif /* LIB_HH */ 27 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/src/lua.cc: -------------------------------------------------------------------------------- 1 | #include "lua.hh" 2 | 3 | namespace lua { 4 | 5 | } /* namespace lua */ 6 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/src/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/src/lua_ffi_module.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/elua/plugin/cffi-lua/src/lua_ffi_module.c -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/src/main.cc: -------------------------------------------------------------------------------- 1 | /* This file exists as it may be compiled in multiple versions depending on 2 | * how the entry point is exported. This is particularly true on Windows, where 3 | * when compiling as DLL, the 'luaopen_cffi' symbol must be dllexport, while 4 | * for a static lib it must be unmarked. 5 | * 6 | * On Unix-like platforms, all symbols are hidden by default if supported by 7 | * the compiler, with 'luaopen_cffi' being the sole visible symbol, this is 8 | * not dependent on how we're compiling it. 9 | */ 10 | 11 | #include "lua.hh" 12 | 13 | #if defined(__CYGWIN__) || (defined(_WIN32) && !defined(_XBOX_VER)) 14 | # ifdef CFFI_LUA_DLL 15 | # define CFFI_LUA_EXPORT __declspec(dllexport) 16 | # else 17 | # define CFFI_LUA_EXPORT 18 | # endif 19 | #else 20 | # if defined(__GNUC__) && (__GNUC__ >= 4) 21 | # define CFFI_LUA_EXPORT __attribute__((visibility("default"))) 22 | # else 23 | # define CFFI_LUA_EXPORT 24 | # endif 25 | #endif 26 | 27 | void ffi_module_open(lua_State *L); 28 | 29 | extern "C" CFFI_LUA_EXPORT int luaopen_cffi(lua_State *L) { 30 | ffi_module_open(L); 31 | return 1; 32 | } 33 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/src/parser.hh: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_HH 2 | #define PARSER_HH 3 | 4 | #include "lua.hh" 5 | #include "ast.hh" 6 | 7 | namespace parser { 8 | 9 | void init(lua_State *L); 10 | 11 | void parse( 12 | lua_State *L, char const *input, char const *iend = nullptr, int paridx = -1 13 | ); 14 | 15 | ast::c_type parse_type( 16 | lua_State *L, char const *input, char const *iend = nullptr, int paridx = -1 17 | ); 18 | 19 | ast::c_expr_type parse_number( 20 | lua_State *L, ast::c_value &v, char const *input, char const *iend = nullptr 21 | ); 22 | 23 | } /* namespace parser */ 24 | 25 | #endif /* PARSER_HH */ 26 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/abi.lua: -------------------------------------------------------------------------------- 1 | -- ffi.os, ffi.arch is not tested as that will vary by platform 2 | -- same with other ffi.abi parameters, etc 3 | 4 | local ffi = require("cffi") 5 | 6 | if ffi.abi("be") then 7 | assert(not ffi.abi("le")) 8 | else 9 | assert(ffi.abi("le")) 10 | assert(not ffi.abi("be")) 11 | end 12 | 13 | if ffi.abi("64bit") then 14 | assert(ffi.sizeof("void *") == 8) 15 | elseif ffi.abi("32bit") then 16 | assert(ffi.sizeof("void *") == 4) 17 | else 18 | skip_test() 19 | end 20 | 21 | assert(ffi.sizeof("char") == 1) 22 | assert(ffi.sizeof("short") == 2) 23 | 24 | ffi.cdef [[ 25 | union foo { 26 | struct { uint8_t a; uint8_t b; }; 27 | uint16_t v; 28 | }; 29 | ]] 30 | 31 | local x = ffi.new("union foo") 32 | x.a = 0xAA 33 | x.b = 0xFF 34 | 35 | if ffi.abi("be") then 36 | assert(x.v == 0xAAFF) 37 | else 38 | assert(x.v == 0xFFAA) 39 | end 40 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/callbacks.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | -- named args 4 | local called = false 5 | local cb = ffi.cast("void (*)(char const *arg1, int arg2)", function(arg1, arg2) 6 | assert(ffi.string(arg1) == "hello world") 7 | assert(ffi.tonumber(arg2) == 5) 8 | called = true 9 | end) 10 | 11 | cb("hello world", 5) 12 | assert(called) 13 | 14 | -- setting different callback 15 | local called2 = false 16 | cb:set(function() called2 = true end) 17 | 18 | cb("foo", 10) 19 | assert(called2) 20 | 21 | cb:free() 22 | 23 | -- unnamed args 24 | local called3 = false 25 | local cb2 = ffi.cast("void (*)(int, double)", function(a, b) 26 | assert(a == 5) 27 | assert(b == 3.14) 28 | called3 = true 29 | end) 30 | 31 | cb2(5, 3.14) 32 | assert(called3) 33 | 34 | cb2:free() 35 | 36 | -- funcs in structs 37 | 38 | ffi.cdef [[ 39 | struct test { 40 | void (*cb)(); 41 | }; 42 | ]] 43 | 44 | local st = ffi.new("struct test") 45 | 46 | local called, called2 = false, false 47 | 48 | -- this also works, but it will leak memory! 49 | --st.cb = function() called = true end 50 | --assert(not called) 51 | --st.cb() 52 | --assert(called) 53 | 54 | local cb3 = ffi.cast("void (*)()", function() called2 = true end) 55 | st.cb = cb3 56 | assert(not called2) 57 | st.cb() 58 | assert(called2) 59 | cb3:free() 60 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/callconv.lua: -------------------------------------------------------------------------------- 1 | -- calling convention specifiers are ignored except on 32-bit x86 windows 2 | 3 | local ffi = require("cffi") 4 | 5 | local L = require("testlib") 6 | 7 | ffi.cdef [[ 8 | int __stdcall test_stdcall(int, int); 9 | int test_fastcall1(int, int) __attribute__((fastcall)) __asm__("test_fastcall"); 10 | __attribute__((fastcall)) int test_fastcall2(int, int) __asm__("test_fastcall"); 11 | int __fastcall test_fastcall3(int, int) __asm__("test_fastcall"); 12 | int __attribute__((fastcall)) test_fastcall4(int, int) __asm__("test_fastcall"); 13 | ]] 14 | 15 | local r = L.test_stdcall(5, 10) 16 | assert(r == 15) 17 | 18 | local r = L.test_fastcall1(5, 10) 19 | assert(r == 15) 20 | 21 | local r = L.test_fastcall2(5, 10) 22 | assert(r == 15) 23 | 24 | local r = L.test_fastcall3(5, 10) 25 | assert(r == 15) 26 | 27 | local r = L.test_fastcall4(5, 10) 28 | assert(r == 15) 29 | 30 | local fp1 = ffi.cast("int (__fastcall *)(int, int)", L.test_fastcall1) 31 | local fp2 = ffi.cast("int (*)(int, int) __attribute__((fastcall))", L.test_fastcall1) 32 | 33 | assert(fp1(15, 20) == 35) 34 | assert(fp2(15, 20) == 35) 35 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/cast.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | -- strings are convertible to char pointers 4 | 5 | local foo = "hello world" 6 | local foop = ffi.cast("const char *", foo) 7 | 8 | assert(ffi.string(foop) == "hello world") 9 | 10 | -- pointer<->number conversions 11 | 12 | local up = ffi.cast("uintptr_t", foop) 13 | local op = ffi.cast("const char *", up) 14 | 15 | assert(ffi.string(op) == "hello world") 16 | assert(op == foop) 17 | 18 | -- passing pointers as arrays is ok 19 | 20 | local x = ffi.new("int[2]", {5, 10}) 21 | local xp = ffi.cast("int *", x) 22 | 23 | local tap = ffi.cast("void (*)(int p[2])", function(p) 24 | assert((p[0] == 5) and (p[1] == 10)) 25 | end) 26 | 27 | tap(x) 28 | tap(xp) 29 | 30 | tap:free() 31 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/cexpr.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | ffi.cdef [[ 4 | typedef enum { 5 | A = 1 << 0, 6 | B = 1 << 1, 7 | AB = A | B, 8 | C = 1 << 2, 9 | D = 1 << 3, 10 | E = 1 << 4, 11 | F = 1 << 5, 12 | G = 1 << 6, 13 | AC = A | C, 14 | ABC = AB | C, 15 | ALL = ABC | D | E | F | G 16 | } Test; 17 | ]] 18 | 19 | assert(ffi.C.A == 1) 20 | assert(ffi.C.B == 2) 21 | assert(ffi.C.AB == 3) 22 | assert(ffi.C.C == 4) 23 | assert(ffi.C.D == 8) 24 | assert(ffi.C.E == 16) 25 | assert(ffi.C.F == 32) 26 | assert(ffi.C.G == 64) 27 | assert(ffi.C.AC == 5) 28 | assert(ffi.C.ABC == 7) 29 | assert(ffi.C.ALL == 127) 30 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/copy_fill.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | local buf = ffi.new("char[256]") 4 | assert(ffi.sizeof(buf) == 256) 5 | 6 | ffi.copy(buf, "hello world") 7 | assert(ffi.string(buf) == "hello world") 8 | assert(ffi.string(buf + 6) == "world") 9 | 10 | ffi.fill(buf, ffi.sizeof(buf)) 11 | assert(ffi.string(buf) == "") 12 | 13 | ffi.fill(buf, 8, string.byte("A")) 14 | assert(ffi.string(buf) == "AAAAAAAA") 15 | 16 | ffi.fill(buf, 32) 17 | ffi.copy(buf, "hello world", 5) 18 | assert(ffi.string(buf) == "hello") 19 | 20 | -- https://github.com/q66/cffi-lua/issues/10 21 | -- make sure passing through lua strings works 22 | assert(ffi.string("hello world") == "hello world") 23 | assert(ffi.string("hello world", 4) == "hell") 24 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/globals.lua: -------------------------------------------------------------------------------- 1 | local ffi = require('cffi') 2 | 3 | ffi.cdef [[ 4 | extern char const test_string[]; 5 | extern int const test_ints[3]; 6 | ]] 7 | 8 | local L = require("testlib") 9 | 10 | assert(L.test_string[0] == string.byte('f')) 11 | assert(L.test_string[1] == string.byte('o')) 12 | assert(L.test_string[2] == string.byte('o')) 13 | 14 | assert(L.test_ints[0] == 42) 15 | assert(L.test_ints[1] == 43) 16 | assert(L.test_ints[2] == 44) 17 | 18 | -- must be references 19 | assert(tostring(ffi.typeof(L.test_string)) == "ctype") 20 | assert(tostring(ffi.typeof(L.test_ints)) == "ctype") 21 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/metatype.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | ffi.cdef [[ 4 | typedef struct foo { 5 | int x; 6 | int y; 7 | } foo; 8 | ]] 9 | 10 | local new_called = 0 11 | 12 | local foo = ffi.metatype("foo", { 13 | __new = function(self, x, y) 14 | new_called = new_called + 1 15 | return ffi.new("foo", x, y) 16 | end, 17 | 18 | __index = { 19 | named_ctor = function(x, y) 20 | return ffi.new("foo", x, y) 21 | end, 22 | 23 | sum = function(self) 24 | return self.x + self.y 25 | end 26 | }, 27 | 28 | __len = function(self) return self.x end, 29 | __unm = function(self) return self.y end, 30 | }) 31 | 32 | assert(new_called == 0) 33 | 34 | local x = foo(5, 10) 35 | assert(x.x == 5) 36 | assert(x.y == 10) 37 | assert(x:sum() == 15) 38 | assert(#x == 5) 39 | assert(-x == 10) 40 | 41 | assert(new_called == 1) 42 | 43 | local x = foo(5, 10) 44 | assert(new_called == 2) 45 | 46 | local x = foo.named_ctor(500, 1000) 47 | assert(x.x == 500) 48 | assert(x.y == 1000) 49 | assert(x:sum() == 1500) 50 | 51 | assert(new_called == 2) 52 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/metatype54.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | ffi.cdef [[ 4 | typedef struct foo { 5 | int x; 6 | } foo; 7 | ]] 8 | 9 | local closed_count = 0 10 | 11 | local foo = ffi.metatype("foo", { 12 | __close = function() 13 | closed_count = closed_count + 1 14 | end, 15 | __name = "foo" 16 | }) 17 | 18 | local x = foo(5) 19 | assert(closed_count == 0) 20 | assert(tostring(x):match("^foo: ")) 21 | 22 | do 23 | local x = foo(5) 24 | end 25 | assert(closed_count == 1) 26 | 27 | do 28 | local x = foo(5) 29 | local y = foo(5) 30 | do 31 | local z = foo(5) 32 | end 33 | assert(closed_count == 2) 34 | end 35 | 36 | assert(closed_count == 4) 37 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/parameterized.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | -- parameterized struct 4 | 5 | local t1_t = ffi.typeof("int") 6 | local t2_t = ffi.typeof("short") 7 | local t3_t = ffi.typeof("char const *") 8 | 9 | ffi.cdef([[ 10 | typedef struct $ { 11 | $ $; 12 | $ $, $; 13 | $ $; 14 | } $; 15 | ]], "pstruct", t1_t, "test1", t2_t, "x", "y", t3_t, "test2", "pstruct") 16 | 17 | local x = ffi.new("pstruct") 18 | x.test1 = 1337 19 | local t2 = "test string" 20 | x.test2 = t2 21 | x.x = 5 22 | x.y = 10 23 | 24 | assert(ffi.tonumber(x.test1) == 1337) 25 | assert(ffi.string(x.test2) == "test string") 26 | assert(ffi.tonumber(x.x) == 5) 27 | assert(ffi.tonumber(x.y) == 10) 28 | 29 | assert(ffi.sizeof("pstruct") == ffi.sizeof( 30 | "struct { int x; short a, b; void *y; }" 31 | )) 32 | 33 | -- parameterized enum 34 | 35 | ffi.cdef([[ 36 | enum { 37 | $ = $, $ 38 | }; 39 | ]], "FOO", 1337, "BAR") 40 | 41 | assert(ffi.C.FOO == 1337) 42 | assert(ffi.C.BAR == 1338) 43 | 44 | -- https://github.com/q66/cffi-lua/issues/6 45 | 46 | assert(tostring(ffi.typeof("$ *", ffi.typeof("int"))) == "ctype") 47 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/redir.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | local L = require("testlib") 3 | 4 | ffi.cdef [[ 5 | int foo(char *buf, size_t n, char const *fmt, ...) __asm__("test_snprintf"); 6 | ]] 7 | 8 | local buf = ffi.new("char[256]") 9 | local ret = L.foo(ffi.cast("char *", buf), 256, "%s", "test") 10 | assert(ret == 4) 11 | assert(ffi.string(buf) == "test") 12 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/simple.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | local L = require("testlib") 3 | 4 | ffi.cdef [[ 5 | size_t test_strlen(char const *str); 6 | size_t test_strlen_void(void const *str) __asm__("test_strlen"); 7 | ]] 8 | 9 | local ret = ffi.tonumber(L.test_strlen("hello world")) 10 | assert(ret == 11) 11 | 12 | local ret = ffi.tonumber(L.test_strlen_void("hello world")) 13 | assert(ret == 11) 14 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/struct_pass.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | ffi.cdef [[ 4 | typedef struct pass { 5 | int a, b; 6 | } pass; 7 | 8 | pass test_struct_val(pass a, pass b); 9 | ]] 10 | 11 | local L = require("testlib") 12 | 13 | local a = ffi.new("pass", 5, 10) 14 | local b = ffi.new("pass", 50, 100) 15 | 16 | local c = L.test_struct_val(a, b) 17 | 18 | assert(c.a == 55) 19 | assert(c.b == 110) 20 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/testlib.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | local tlp = os.getenv("TESTLIB_PATH") 4 | if not tlp or (#tlp == 0) then 5 | skip_test() 6 | end 7 | 8 | return ffi.load(tlp) 9 | -------------------------------------------------------------------------------- /components/elua/plugin/cffi-lua/tests/variadic.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("cffi") 2 | 3 | ffi.cdef [[ 4 | int test_snprintf(char *buf, size_t n, char const *fmt, ...); 5 | ]] 6 | 7 | local L = require("testlib") 8 | 9 | local buf = ffi.new("char[256]") 10 | local bufs = ffi.sizeof(buf) 11 | assert(bufs == 256) 12 | 13 | local ret = L.test_snprintf(ffi.cast("char *", buf), bufs, "%s", "test") 14 | assert(ret == 4) 15 | assert(ffi.string(buf) == "test") 16 | local ret = L.test_snprintf(buf, bufs, "%d", ffi.new("int", 123456)) 17 | assert(ret == 6) 18 | assert(ffi.string(buf) == "123456") 19 | 20 | local ret = L.test_snprintf(buf, bufs, "%s %g", "hello", 3.14) 21 | assert(ret == 10) 22 | assert(ffi.string(buf) == "hello 3.14") 23 | -------------------------------------------------------------------------------- /components/modules/libffi/.gitignore: -------------------------------------------------------------------------------- 1 | include/ffi.h 2 | include/ffitarget.h 3 | build/ 4 | makefiles.mk~ 5 | makefiles.out~ 6 | makefiles.sed~ -------------------------------------------------------------------------------- /components/modules/libffi/LICENSE: -------------------------------------------------------------------------------- 1 | libffi - Copyright (c) 1996-2024 Anthony Green, Red Hat, Inc and others. 2 | See source files for details. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | ``Software''), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/modules/libffi/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec autoreconf -v -i 3 | -------------------------------------------------------------------------------- /components/modules/libffi/doc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this with automake to create Makefile.in 2 | 3 | info_TEXINFOS = libffi.texi 4 | -------------------------------------------------------------------------------- /components/modules/libffi/doc/version.texi: -------------------------------------------------------------------------------- 1 | @set UPDATED 15 February 2024 2 | @set UPDATED-MONTH February 2024 3 | @set EDITION 3.4.6 4 | @set VERSION 3.4.6 5 | -------------------------------------------------------------------------------- /components/modules/libffi/include/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this with automake to create Makefile.in 2 | 3 | AUTOMAKE_OPTIONS=foreign 4 | 5 | DISTCLEANFILES=ffitarget.h 6 | noinst_HEADERS=ffi_common.h ffi_cfi.h tramp.h 7 | EXTRA_DIST=ffi.h.in 8 | 9 | nodist_include_HEADERS = ffi.h ffitarget.h 10 | -------------------------------------------------------------------------------- /components/modules/libffi/libffi.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | toolexeclibdir=@toolexeclibdir@ 5 | includedir=@includedir@ 6 | 7 | Name: @PACKAGE_NAME@ 8 | Description: Library supporting Foreign Function Interfaces 9 | Version: @PACKAGE_VERSION@ 10 | Libs: -L${toolexeclibdir} -lffi 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /components/modules/libffi/libtool-version: -------------------------------------------------------------------------------- 1 | # This file is used to maintain libtool version info for libffi. See 2 | # the libtool manual to understand the meaning of the fields. This is 3 | # a separate file so that version updates don't involve re-running 4 | # automake. 5 | # 6 | # Here are a set of rules to help you update your library version 7 | # information: 8 | # 9 | # 1. Start with version information of `0:0:0' for each libtool library. 10 | # 11 | # 2. Update the version information only immediately before a public 12 | # release of your software. More frequent updates are unnecessary, 13 | # and only guarantee that the current interface number gets larger 14 | # faster. 15 | # 16 | # 3. If the library source code has changed at all since the last 17 | # update, then increment revision (`c:r:a' becomes `c:r+1:a'). 18 | # 19 | # 4. If any interfaces have been added, removed, or changed since the 20 | # last update, increment current, and set revision to 0. 21 | # 22 | # 5. If any interfaces have been added since the last public release, 23 | # then increment age. 24 | # 25 | # 6. If any interfaces have been removed since the last public 26 | # release, then set age to 0. 27 | # 28 | # CURRENT:REVISION:AGE 29 | 9:4:1 30 | -------------------------------------------------------------------------------- /components/modules/libffi/m4/asmcfi.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([GCC_AS_CFI_PSEUDO_OP], 2 | [AC_CACHE_CHECK([assembler .cfi pseudo-op support], 3 | gcc_cv_as_cfi_pseudo_op, [ 4 | gcc_cv_as_cfi_pseudo_op=unknown 5 | AC_TRY_COMPILE([asm (".cfi_sections\n\t.cfi_startproc\n\t.cfi_endproc");],, 6 | [gcc_cv_as_cfi_pseudo_op=yes], 7 | [gcc_cv_as_cfi_pseudo_op=no]) 8 | ]) 9 | if test "x$gcc_cv_as_cfi_pseudo_op" = xyes; then 10 | AC_DEFINE(HAVE_AS_CFI_PSEUDO_OP, 1, 11 | [Define if your assembler supports .cfi_* directives.]) 12 | fi 13 | ]) 14 | -------------------------------------------------------------------------------- /components/modules/libffi/m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 4179 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.6]) 16 | m4_define([LT_PACKAGE_REVISION], [2.4.6]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.6' 20 | macro_revision='2.4.6' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /components/modules/libffi/man/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this with automake to create Makefile.in 2 | 3 | AUTOMAKE_OPTIONS=foreign 4 | 5 | EXTRA_DIST = ffi.3 ffi_call.3 ffi_prep_cif.3 ffi_prep_cif_var.3 6 | 7 | man_MANS = ffi.3 ffi_call.3 ffi_prep_cif.3 ffi_prep_cif_var.3 8 | 9 | -------------------------------------------------------------------------------- /components/modules/libffi/man/ffi.3: -------------------------------------------------------------------------------- 1 | .Dd February 15, 2008 2 | .Dt FFI 3 3 | .Sh NAME 4 | .Nm FFI 5 | .Nd Foreign Function Interface 6 | .Sh LIBRARY 7 | libffi, -lffi 8 | .Sh SYNOPSIS 9 | .In ffi.h 10 | .Ft ffi_status 11 | .Fo ffi_prep_cif 12 | .Fa "ffi_cif *cif" 13 | .Fa "ffi_abi abi" 14 | .Fa "unsigned int nargs" 15 | .Fa "ffi_type *rtype" 16 | .Fa "ffi_type **atypes" 17 | .Fc 18 | .Ft void 19 | .Fo ffi_prep_cif_var 20 | .Fa "ffi_cif *cif" 21 | .Fa "ffi_abi abi" 22 | .Fa "unsigned int nfixedargs" 23 | .Fa "unsigned int ntotalargs" 24 | .Fa "ffi_type *rtype" 25 | .Fa "ffi_type **atypes" 26 | .Fc 27 | .Ft void 28 | .Fo ffi_call 29 | .Fa "ffi_cif *cif" 30 | .Fa "void (*fn)(void)" 31 | .Fa "void *rvalue" 32 | .Fa "void **avalue" 33 | .Fc 34 | .Sh DESCRIPTION 35 | The foreign function interface provides a mechanism by which a function can 36 | generate a call to another function at runtime without requiring knowledge of 37 | the called function's interface at compile time. 38 | .Sh SEE ALSO 39 | .Xr ffi_prep_cif 3 , 40 | .Xr ffi_prep_cif_var 3 , 41 | .Xr ffi_call 3 42 | -------------------------------------------------------------------------------- /components/modules/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /components/modules/libffi/src/alpha/internal.h: -------------------------------------------------------------------------------- 1 | #define ALPHA_ST_VOID 0 2 | #define ALPHA_ST_INT 1 3 | #define ALPHA_ST_FLOAT 2 4 | #define ALPHA_ST_DOUBLE 3 5 | #define ALPHA_ST_CPLXF 4 6 | #define ALPHA_ST_CPLXD 5 7 | 8 | #define ALPHA_LD_VOID 0 9 | #define ALPHA_LD_INT64 1 10 | #define ALPHA_LD_INT32 2 11 | #define ALPHA_LD_UINT16 3 12 | #define ALPHA_LD_SINT16 4 13 | #define ALPHA_LD_UINT8 5 14 | #define ALPHA_LD_SINT8 6 15 | #define ALPHA_LD_FLOAT 7 16 | #define ALPHA_LD_DOUBLE 8 17 | #define ALPHA_LD_CPLXF 9 18 | #define ALPHA_LD_CPLXD 10 19 | 20 | #define ALPHA_ST_SHIFT 0 21 | #define ALPHA_LD_SHIFT 8 22 | #define ALPHA_RET_IN_MEM 0x10000 23 | #define ALPHA_FLAGS(S, L) (((L) << ALPHA_LD_SHIFT) | (S)) 24 | -------------------------------------------------------------------------------- /components/modules/libffi/src/arm/internal.h: -------------------------------------------------------------------------------- 1 | #define ARM_TYPE_VFP_S 0 2 | #define ARM_TYPE_VFP_D 1 3 | #define ARM_TYPE_VFP_N 2 4 | #define ARM_TYPE_INT64 3 5 | #define ARM_TYPE_INT 4 6 | #define ARM_TYPE_VOID 5 7 | #define ARM_TYPE_STRUCT 6 8 | 9 | #if defined(FFI_EXEC_STATIC_TRAMP) 10 | /* 11 | * For the trampoline table mapping, a mapping size of 4K (base page size) 12 | * is chosen. 13 | */ 14 | #define ARM_TRAMP_MAP_SHIFT 12 15 | #define ARM_TRAMP_MAP_SIZE (1 << ARM_TRAMP_MAP_SHIFT) 16 | #define ARM_TRAMP_SIZE 20 17 | #endif 18 | -------------------------------------------------------------------------------- /components/modules/libffi/src/kvx/asm.h: -------------------------------------------------------------------------------- 1 | /* args are passed on registers from r0 up to r11 => 12*8 bytes */ 2 | #define REG_ARGS_SIZE (12*8) 3 | #define KVX_REGISTER_SIZE (8) 4 | #define KVX_ABI_SLOT_SIZE (KVX_REGISTER_SIZE) 5 | #define KVX_ABI_MAX_AGGREGATE_IN_REG_SIZE (4*KVX_ABI_SLOT_SIZE) 6 | -------------------------------------------------------------------------------- /components/modules/libffi/src/powerpc/t-aix: -------------------------------------------------------------------------------- 1 | # This file is needed by GCC in order to correctly build AIX FAT 2 | # library for libffi. 3 | # However, it has no sense to include this code here, as it depends 4 | # on GCC multilib architecture. 5 | # Thus, this file is a simple stub replaced in GCC repository. 6 | -------------------------------------------------------------------------------- /components/modules/libffi/src/s390/internal.h: -------------------------------------------------------------------------------- 1 | /* If these values change, sysv.S must be adapted! */ 2 | #define FFI390_RET_DOUBLE 0 3 | #define FFI390_RET_FLOAT 1 4 | #define FFI390_RET_INT64 2 5 | #define FFI390_RET_INT32 3 6 | #define FFI390_RET_VOID 4 7 | 8 | #define FFI360_RET_MASK 7 9 | #define FFI390_RET_IN_MEM 8 10 | 11 | #define FFI390_RET_STRUCT (FFI390_RET_VOID | FFI390_RET_IN_MEM) 12 | -------------------------------------------------------------------------------- /components/modules/libffi/src/sparc/internal.h: -------------------------------------------------------------------------------- 1 | #define SPARC_RET_VOID 0 2 | #define SPARC_RET_STRUCT 1 3 | #define SPARC_RET_UINT8 2 4 | #define SPARC_RET_SINT8 3 5 | #define SPARC_RET_UINT16 4 6 | #define SPARC_RET_SINT16 5 7 | #define SPARC_RET_UINT32 6 8 | #define SP_V9_RET_SINT32 7 /* v9 only */ 9 | #define SP_V8_RET_CPLX16 7 /* v8 only */ 10 | #define SPARC_RET_INT64 8 11 | #define SPARC_RET_INT128 9 12 | 13 | /* Note that F_7 is missing, and is handled by SPARC_RET_STRUCT. */ 14 | #define SPARC_RET_F_8 10 15 | #define SPARC_RET_F_6 11 16 | #define SPARC_RET_F_4 12 17 | #define SPARC_RET_F_2 13 18 | #define SP_V9_RET_F_3 14 /* v9 only */ 19 | #define SP_V8_RET_CPLX8 14 /* v8 only */ 20 | #define SPARC_RET_F_1 15 21 | 22 | #define SPARC_FLAG_RET_MASK 15 23 | #define SPARC_FLAG_RET_IN_MEM 32 24 | #define SPARC_FLAG_FP_ARGS 64 25 | 26 | #define SPARC_SIZEMASK_SHIFT 8 27 | -------------------------------------------------------------------------------- /components/modules/libffi/src/x86/asmnames.h: -------------------------------------------------------------------------------- 1 | #ifndef ASMNAMES_H 2 | #define ASMNAMES_H 3 | 4 | #define C2(X, Y) X ## Y 5 | #define C1(X, Y) C2(X, Y) 6 | #ifdef __USER_LABEL_PREFIX__ 7 | # define C(X) C1(__USER_LABEL_PREFIX__, X) 8 | #else 9 | # define C(X) X 10 | #endif 11 | 12 | #ifdef __APPLE__ 13 | # define L(X) C1(L, X) 14 | #else 15 | # define L(X) C1(.L, X) 16 | #endif 17 | 18 | #if defined(__ELF__) && defined(__PIC__) 19 | # define PLT(X) X@PLT 20 | #else 21 | # define PLT(X) X 22 | #endif 23 | 24 | #ifdef __ELF__ 25 | # define ENDF(X) .type X,@function; .size X, . - X 26 | #else 27 | # define ENDF(X) 28 | #endif 29 | 30 | #endif /* ASMNAMES_H */ 31 | -------------------------------------------------------------------------------- /components/modules/libffi/src/x86/internal.h: -------------------------------------------------------------------------------- 1 | #define X86_RET_FLOAT 0 2 | #define X86_RET_DOUBLE 1 3 | #define X86_RET_LDOUBLE 2 4 | #define X86_RET_SINT8 3 5 | #define X86_RET_SINT16 4 6 | #define X86_RET_UINT8 5 7 | #define X86_RET_UINT16 6 8 | #define X86_RET_INT64 7 9 | #define X86_RET_INT32 8 10 | #define X86_RET_VOID 9 11 | #define X86_RET_STRUCTPOP 10 12 | #define X86_RET_STRUCTARG 11 13 | #define X86_RET_STRUCT_1B 12 14 | #define X86_RET_STRUCT_2B 13 15 | #define X86_RET_UNUSED14 14 16 | #define X86_RET_UNUSED15 15 17 | 18 | #define X86_RET_TYPE_MASK 15 19 | #define X86_RET_POP_SHIFT 4 20 | 21 | #define R_EAX 0 22 | #define R_EDX 1 23 | #define R_ECX 2 24 | 25 | #ifdef __PCC__ 26 | # define HAVE_FASTCALL 0 27 | #else 28 | # define HAVE_FASTCALL 1 29 | #endif 30 | 31 | #if defined(FFI_EXEC_STATIC_TRAMP) 32 | /* 33 | * For the trampoline code table mapping, a mapping size of 4K (base page size) 34 | * is chosen. 35 | */ 36 | #define X86_TRAMP_MAP_SHIFT 12 37 | #define X86_TRAMP_MAP_SIZE (1 << X86_TRAMP_MAP_SHIFT) 38 | #ifdef ENDBR_PRESENT 39 | #define X86_TRAMP_SIZE 44 40 | #else 41 | #define X86_TRAMP_SIZE 40 42 | #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /components/modules/libffi/src/x86/internal64.h: -------------------------------------------------------------------------------- 1 | #define UNIX64_RET_VOID 0 2 | #define UNIX64_RET_UINT8 1 3 | #define UNIX64_RET_UINT16 2 4 | #define UNIX64_RET_UINT32 3 5 | #define UNIX64_RET_SINT8 4 6 | #define UNIX64_RET_SINT16 5 7 | #define UNIX64_RET_SINT32 6 8 | #define UNIX64_RET_INT64 7 9 | #define UNIX64_RET_XMM32 8 10 | #define UNIX64_RET_XMM64 9 11 | #define UNIX64_RET_X87 10 12 | #define UNIX64_RET_X87_2 11 13 | #define UNIX64_RET_ST_XMM0_RAX 12 14 | #define UNIX64_RET_ST_RAX_XMM0 13 15 | #define UNIX64_RET_ST_XMM0_XMM1 14 16 | #define UNIX64_RET_ST_RAX_RDX 15 17 | 18 | #define UNIX64_RET_LAST 15 19 | 20 | #define UNIX64_FLAG_RET_IN_MEM (1 << 10) 21 | #define UNIX64_FLAG_XMM_ARGS (1 << 11) 22 | #define UNIX64_SIZE_SHIFT 12 23 | 24 | #if defined(FFI_EXEC_STATIC_TRAMP) 25 | /* 26 | * For the trampoline code table mapping, a mapping size of 4K (base page size) 27 | * is chosen. 28 | */ 29 | #define UNIX64_TRAMP_MAP_SHIFT 12 30 | #define UNIX64_TRAMP_MAP_SIZE (1 << UNIX64_TRAMP_MAP_SHIFT) 31 | #ifdef ENDBR_PRESENT 32 | #define UNIX64_TRAMP_SIZE 40 33 | #else 34 | #define UNIX64_TRAMP_SIZE 32 35 | #endif 36 | #endif 37 | -------------------------------------------------------------------------------- /components/modules/libffi/stamp-h.in: -------------------------------------------------------------------------------- 1 | timestamp 2 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/config/default.exp: -------------------------------------------------------------------------------- 1 | load_lib "standard.exp" 2 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/emscripten/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.bhaible/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -O2 -Wall 3 | prefix = 4 | includedir = $(prefix)/include 5 | libdir = $(prefix)/lib 6 | CPPFLAGS = -I$(includedir) 7 | LDFLAGS = -L$(libdir) -Wl,-rpath,$(libdir) 8 | 9 | all: check-call check-callback 10 | 11 | test-call: test-call.c testcases.c 12 | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o test-call test-call.c -lffi 13 | 14 | test-callback: test-callback.c testcases.c 15 | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o test-callback test-callback.c -lffi 16 | 17 | check-call: test-call 18 | ./test-call > test-call.out 19 | LC_ALL=C uniq -u < test-call.out > failed-call 20 | test '!' -s failed-call 21 | 22 | check-callback: test-callback 23 | ./test-callback > test-callback.out 24 | LC_ALL=C uniq -u < test-callback.out > failed-callback 25 | test '!' -s failed-callback 26 | 27 | clean: 28 | rm -f test-call test-callback test-call.out test-callback.out failed-call failed-callback 29 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/align_mixed.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check for proper argument alignment. 3 | Limitations: none. 4 | PR: none. 5 | Originator: (from many_win32.c) */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static float ABI_ATTR align_arguments(int i1, 12 | double f2, 13 | int i3, 14 | double f4) 15 | { 16 | return i1+f2+i3+f4; 17 | } 18 | 19 | int main(void) 20 | { 21 | ffi_cif cif; 22 | ffi_type *args[4] = { 23 | &ffi_type_sint, 24 | &ffi_type_double, 25 | &ffi_type_sint, 26 | &ffi_type_double 27 | }; 28 | double fa[2] = {1,2}; 29 | int ia[2] = {1,2}; 30 | void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]}; 31 | float f, ff; 32 | 33 | /* Initialize the cif */ 34 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 4, 35 | &ffi_type_float, args) == FFI_OK); 36 | 37 | ff = align_arguments(ia[0], fa[0], ia[1], fa[1]); 38 | 39 | ffi_call(&cif, FFI_FN(align_arguments), &f, values); 40 | 41 | if (f == ff) 42 | printf("align arguments tests ok!\n"); 43 | else 44 | CHECK(0); 45 | exit(0); 46 | } 47 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/align_stdcall.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check for proper argument alignment. 3 | Limitations: none. 4 | PR: none. 5 | Originator: (from many_win32.c) */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static float ABI_ATTR align_arguments(int i1, 12 | double f2, 13 | int i3, 14 | double f4) 15 | { 16 | return i1+f2+i3+f4; 17 | } 18 | 19 | int main(void) 20 | { 21 | ffi_cif cif; 22 | ffi_type *args[4] = { 23 | &ffi_type_sint, 24 | &ffi_type_double, 25 | &ffi_type_sint, 26 | &ffi_type_double 27 | }; 28 | double fa[2] = {1,2}; 29 | int ia[2] = {1,2}; 30 | void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]}; 31 | float f, ff; 32 | 33 | /* Initialize the cif */ 34 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 4, 35 | &ffi_type_float, args) == FFI_OK); 36 | 37 | ff = align_arguments(ia[0], fa[0], ia[1], fa[1]);; 38 | 39 | ffi_call(&cif, FFI_FN(align_arguments), &f, values); 40 | 41 | if (f == ff) 42 | printf("align arguments tests ok!\n"); 43 | else 44 | CHECK(0); 45 | exit(0); 46 | } 47 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/bpo_38748.c: -------------------------------------------------------------------------------- 1 | /* Area: bpo-38748 2 | Purpose: test for stdcall alignment problem 3 | Source: github.com/python/cpython/pull/26204 */ 4 | 5 | /* { dg-do run } */ 6 | 7 | #include "ffitest.h" 8 | #include "ffi_common.h" 9 | 10 | static UINT32 ABI_ATTR align_arguments(UINT32 l1, 11 | UINT64 l2) 12 | { 13 | return l1 + (UINT32) l2; 14 | } 15 | 16 | int main(void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[4] = { 20 | &ffi_type_uint32, 21 | &ffi_type_uint64 22 | }; 23 | ffi_arg lr1, lr2; 24 | UINT32 l1 = 1; 25 | UINT64 l2 = 2; 26 | void *values[2] = {&l1, &l2}; 27 | 28 | /* Initialize the cif */ 29 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, 30 | &ffi_type_uint32, args) == FFI_OK); 31 | 32 | lr1 = align_arguments(l1, l2); 33 | 34 | ffi_call(&cif, FFI_FN(align_arguments), &lr2, values); 35 | 36 | if (lr1 == lr2) 37 | printf("bpo-38748 arguments tests ok!\n"); 38 | else 39 | CHECK(0); 40 | exit(0); 41 | } 42 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/err_bad_typedef.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_prep_cif 2 | Purpose: Test error return for bad typedefs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/6/2007 */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | int main (void) 12 | { 13 | ffi_cif cif; 14 | ffi_type* arg_types[1]; 15 | 16 | ffi_type badType = ffi_type_void; 17 | 18 | arg_types[0] = NULL; 19 | 20 | badType.size = 0; 21 | 22 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &badType, 23 | arg_types) == FFI_BAD_TYPEDEF); 24 | 25 | exit(0); 26 | } 27 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/negint.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check that negative integers are passed correctly. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static int checking(int a, short b, signed char c) 12 | { 13 | 14 | return (a < 0 && b < 0 && c < 0); 15 | } 16 | 17 | int main (void) 18 | { 19 | ffi_cif cif; 20 | ffi_type *args[MAX_ARGS]; 21 | void *values[MAX_ARGS]; 22 | ffi_arg rint; 23 | 24 | signed int si; 25 | signed short ss; 26 | signed char sc; 27 | 28 | args[0] = &ffi_type_sint; 29 | values[0] = &si; 30 | args[1] = &ffi_type_sshort; 31 | values[1] = &ss; 32 | args[2] = &ffi_type_schar; 33 | values[2] = ≻ 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 37 | &ffi_type_sint, args) == FFI_OK); 38 | 39 | si = -6; 40 | ss = -12; 41 | sc = -1; 42 | 43 | checking (si, ss, sc); 44 | 45 | ffi_call(&cif, FFI_FN(checking), &rint, values); 46 | 47 | printf ("%d vs %d\n", (int)rint, checking (si, ss, sc)); 48 | 49 | CHECK(rint != 0); 50 | 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/offsets.c: -------------------------------------------------------------------------------- 1 | /* Area: Struct layout 2 | Purpose: Test ffi_get_struct_offsets 3 | Limitations: none. 4 | PR: none. 5 | Originator: Tom Tromey. */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | #include 10 | 11 | struct test_1 12 | { 13 | char c; 14 | float f; 15 | char c2; 16 | int i; 17 | }; 18 | 19 | int 20 | main (void) 21 | { 22 | ffi_type test_1_type; 23 | ffi_type *test_1_elements[5]; 24 | size_t test_1_offsets[4]; 25 | 26 | test_1_elements[0] = &ffi_type_schar; 27 | test_1_elements[1] = &ffi_type_float; 28 | test_1_elements[2] = &ffi_type_schar; 29 | test_1_elements[3] = &ffi_type_sint; 30 | test_1_elements[4] = NULL; 31 | 32 | test_1_type.size = 0; 33 | test_1_type.alignment = 0; 34 | test_1_type.type = FFI_TYPE_STRUCT; 35 | test_1_type.elements = test_1_elements; 36 | 37 | CHECK (ffi_get_struct_offsets (FFI_DEFAULT_ABI, &test_1_type, test_1_offsets) 38 | == FFI_OK); 39 | CHECK (test_1_type.size == sizeof (struct test_1)); 40 | CHECK (offsetof (struct test_1, c) == test_1_offsets[0]); 41 | CHECK (offsetof (struct test_1, f) == test_1_offsets[1]); 42 | CHECK (offsetof (struct test_1, c2) == test_1_offsets[2]); 43 | CHECK (offsetof (struct test_1, i) == test_1_offsets[3]); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_dbl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static double return_dbl(double dbl) 11 | { 12 | printf ("%f\n", dbl); 13 | return 2 * dbl; 14 | } 15 | int main (void) 16 | { 17 | ffi_cif cif; 18 | ffi_type *args[MAX_ARGS]; 19 | void *values[MAX_ARGS]; 20 | double dbl, rdbl; 21 | 22 | args[0] = &ffi_type_double; 23 | values[0] = &dbl; 24 | 25 | /* Initialize the cif */ 26 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 27 | &ffi_type_double, args) == FFI_OK); 28 | 29 | for (dbl = -127.3; dbl < 127; dbl++) 30 | { 31 | ffi_call(&cif, FFI_FN(return_dbl), &rdbl, values); 32 | printf ("%f vs %f\n", rdbl, return_dbl(dbl)); 33 | CHECK(rdbl == 2 * dbl); 34 | } 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_dbl1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static double return_dbl(double dbl1, float fl2, unsigned int in3, double dbl4) 11 | { 12 | return dbl1 + fl2 + in3 + dbl4; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | double dbl1, dbl4, rdbl; 20 | float fl2; 21 | unsigned int in3; 22 | args[0] = &ffi_type_double; 23 | args[1] = &ffi_type_float; 24 | args[2] = &ffi_type_uint; 25 | args[3] = &ffi_type_double; 26 | values[0] = &dbl1; 27 | values[1] = &fl2; 28 | values[2] = &in3; 29 | values[3] = &dbl4; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 33 | &ffi_type_double, args) == FFI_OK); 34 | dbl1 = 127.0; 35 | fl2 = 128.0; 36 | in3 = 255; 37 | dbl4 = 512.7; 38 | 39 | ffi_call(&cif, FFI_FN(return_dbl), &rdbl, values); 40 | printf ("%f vs %f\n", rdbl, return_dbl(dbl1, fl2, in3, dbl4)); 41 | CHECK(rdbl == dbl1 + fl2 + in3 + dbl4); 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_dbl2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static double return_dbl(double dbl1, double dbl2, unsigned int in3, double dbl4) 11 | { 12 | return dbl1 + dbl2 + in3 + dbl4; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | double dbl1, dbl2, dbl4, rdbl; 20 | unsigned int in3; 21 | args[0] = &ffi_type_double; 22 | args[1] = &ffi_type_double; 23 | args[2] = &ffi_type_uint; 24 | args[3] = &ffi_type_double; 25 | values[0] = &dbl1; 26 | values[1] = &dbl2; 27 | values[2] = &in3; 28 | values[3] = &dbl4; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 32 | &ffi_type_double, args) == FFI_OK); 33 | dbl1 = 127.0; 34 | dbl2 = 128.0; 35 | in3 = 255; 36 | dbl4 = 512.7; 37 | 38 | ffi_call(&cif, FFI_FN(return_dbl), &rdbl, values); 39 | printf ("%f vs %f\n", rdbl, return_dbl(dbl1, dbl2, in3, dbl4)); 40 | CHECK(rdbl == dbl1 + dbl2 + in3 + dbl4); 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_fl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static float return_fl(float fl) 11 | { 12 | return 2 * fl; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | float fl, rfl; 20 | 21 | args[0] = &ffi_type_float; 22 | values[0] = &fl; 23 | 24 | /* Initialize the cif */ 25 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 26 | &ffi_type_float, args) == FFI_OK); 27 | 28 | for (fl = -127.0; fl < 127; fl++) 29 | { 30 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 31 | printf ("%f vs %f\n", rfl, return_fl(fl)); 32 | CHECK(rfl == 2 * fl); 33 | } 34 | exit(0); 35 | } 36 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_fl1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static float return_fl(float fl1, float fl2) 11 | { 12 | return fl1 + fl2; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | float fl1, fl2, rfl; 20 | 21 | args[0] = &ffi_type_float; 22 | args[1] = &ffi_type_float; 23 | values[0] = &fl1; 24 | values[1] = &fl2; 25 | 26 | /* Initialize the cif */ 27 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 28 | &ffi_type_float, args) == FFI_OK); 29 | fl1 = 127.0; 30 | fl2 = 128.0; 31 | 32 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 33 | printf ("%f vs %f\n", rfl, return_fl(fl1, fl2)); 34 | CHECK(rfl == fl1 + fl2); 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_fl2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | /* Use volatile float to avoid false negative on ix86. See PR target/323. */ 11 | static float return_fl(float fl1, float fl2, float fl3, float fl4) 12 | { 13 | volatile float sum; 14 | 15 | sum = fl1 + fl2 + fl3 + fl4; 16 | return sum; 17 | } 18 | int main (void) 19 | { 20 | ffi_cif cif; 21 | ffi_type *args[MAX_ARGS]; 22 | void *values[MAX_ARGS]; 23 | float fl1, fl2, fl3, fl4, rfl; 24 | volatile float sum; 25 | 26 | args[0] = &ffi_type_float; 27 | args[1] = &ffi_type_float; 28 | args[2] = &ffi_type_float; 29 | args[3] = &ffi_type_float; 30 | values[0] = &fl1; 31 | values[1] = &fl2; 32 | values[2] = &fl3; 33 | values[3] = &fl4; 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 37 | &ffi_type_float, args) == FFI_OK); 38 | fl1 = 127.0; 39 | fl2 = 128.0; 40 | fl3 = 255.1; 41 | fl4 = 512.7; 42 | 43 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 44 | printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, fl3, fl4)); 45 | 46 | sum = fl1 + fl2 + fl3 + fl4; 47 | CHECK(rfl == sum); 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_fl3.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static float return_fl(float fl1, float fl2, unsigned int in3, float fl4) 11 | { 12 | return fl1 + fl2 + in3 + fl4; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | float fl1, fl2, fl4, rfl; 20 | unsigned int in3; 21 | args[0] = &ffi_type_float; 22 | args[1] = &ffi_type_float; 23 | args[2] = &ffi_type_uint; 24 | args[3] = &ffi_type_float; 25 | values[0] = &fl1; 26 | values[1] = &fl2; 27 | values[2] = &in3; 28 | values[3] = &fl4; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 32 | &ffi_type_float, args) == FFI_OK); 33 | fl1 = 127.0; 34 | fl2 = 128.0; 35 | in3 = 255; 36 | fl4 = 512.7; 37 | 38 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 39 | printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, in3, fl4)); 40 | CHECK(rfl == fl1 + fl2 + in3 + fl4); 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_ldl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value long double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20071113 */ 6 | /* { dg-do run } */ 7 | 8 | #include "ffitest.h" 9 | 10 | static long double return_ldl(long double ldl) 11 | { 12 | return 2*ldl; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | long double ldl, rldl; 20 | 21 | args[0] = &ffi_type_longdouble; 22 | values[0] = &ldl; 23 | 24 | /* Initialize the cif */ 25 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 26 | &ffi_type_longdouble, args) == FFI_OK); 27 | 28 | for (ldl = -127.0; ldl < 127.0; ldl++) 29 | { 30 | ffi_call(&cif, FFI_FN(return_ldl), &rldl, values); 31 | CHECK(rldl == 2 * ldl); 32 | } 33 | exit(0); 34 | } 35 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_ll.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value long long. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | static long long return_ll(long long ll) 10 | { 11 | return ll; 12 | } 13 | 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | long long rlonglong; 20 | long long ll; 21 | 22 | args[0] = &ffi_type_sint64; 23 | values[0] = ≪ 24 | 25 | /* Initialize the cif */ 26 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 27 | &ffi_type_sint64, args) == FFI_OK); 28 | 29 | for (ll = 0LL; ll < 100LL; ll++) 30 | { 31 | ffi_call(&cif, FFI_FN(return_ll), &rlonglong, values); 32 | CHECK(rlonglong == ll); 33 | } 34 | 35 | for (ll = 55555555555000LL; ll < 55555555555100LL; ll++) 36 | { 37 | ffi_call(&cif, FFI_FN(return_ll), &rlonglong, values); 38 | CHECK(rlonglong == ll); 39 | } 40 | exit(0); 41 | } 42 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_sc.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value signed char. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static signed char return_sc(signed char sc) 11 | { 12 | return sc; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | ffi_arg rint; 20 | signed char sc; 21 | 22 | args[0] = &ffi_type_schar; 23 | values[0] = ≻ 24 | 25 | /* Initialize the cif */ 26 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 27 | &ffi_type_schar, args) == FFI_OK); 28 | 29 | for (sc = (signed char) -127; 30 | sc < (signed char) 127; sc++) 31 | { 32 | ffi_call(&cif, FFI_FN(return_sc), &rint, values); 33 | CHECK((signed char)rint == sc); 34 | } 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_sl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check if long as return type is handled correctly. 3 | Limitations: none. 4 | PR: none. 5 | */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | static long return_sl(long l1, long l2) 10 | { 11 | CHECK(l1 == 1073741823L); 12 | CHECK(l2 == 1073741824L); 13 | return l1 - l2; 14 | } 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[MAX_ARGS]; 20 | void *values[MAX_ARGS]; 21 | ffi_arg res; 22 | unsigned long l1, l2; 23 | 24 | args[0] = &ffi_type_slong; 25 | args[1] = &ffi_type_slong; 26 | values[0] = &l1; 27 | values[1] = &l2; 28 | 29 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 30 | &ffi_type_slong, args) == FFI_OK); 31 | 32 | l1 = 1073741823L; 33 | l2 = 1073741824L; 34 | 35 | ffi_call(&cif, FFI_FN(return_sl), &res, values); 36 | printf("res: %ld, %ld\n", (long)res, l1 - l2); 37 | /* { dg-output "res: -1, -1" } */ 38 | CHECK((long)res == -1); 39 | CHECK(l1 + 1 == l2); 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_uc.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value unsigned char. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static unsigned char return_uc(unsigned char uc) 11 | { 12 | return uc; 13 | } 14 | 15 | int main (void) 16 | { 17 | ffi_cif cif; 18 | ffi_type *args[MAX_ARGS]; 19 | void *values[MAX_ARGS]; 20 | ffi_arg rint; 21 | 22 | unsigned char uc; 23 | 24 | args[0] = &ffi_type_uchar; 25 | values[0] = &uc; 26 | 27 | /* Initialize the cif */ 28 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 29 | &ffi_type_uchar, args) == FFI_OK); 30 | 31 | for (uc = (unsigned char) '\x00'; 32 | uc < (unsigned char) '\xff'; uc++) 33 | { 34 | ffi_call(&cif, FFI_FN(return_uc), &rint, values); 35 | CHECK((unsigned char)rint == uc); 36 | } 37 | exit(0); 38 | } 39 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/return_ul.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check if unsigned long as return type is handled correctly. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20060724 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | static unsigned long return_ul(unsigned long ul1, unsigned long ul2) 10 | { 11 | CHECK(ul1 == 1073741823L); 12 | CHECK(ul2 == 1073741824L); 13 | return ul1 + ul2; 14 | } 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[MAX_ARGS]; 20 | void *values[MAX_ARGS]; 21 | ffi_arg res; 22 | unsigned long ul1, ul2; 23 | 24 | args[0] = &ffi_type_ulong; 25 | args[1] = &ffi_type_ulong; 26 | values[0] = &ul1; 27 | values[1] = &ul2; 28 | 29 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 30 | &ffi_type_ulong, args) == FFI_OK); 31 | 32 | ul1 = 1073741823L; 33 | ul2 = 1073741824L; 34 | 35 | ffi_call(&cif, FFI_FN(return_ul), &res, values); 36 | printf("res: %lu, %lu\n", (unsigned long)res, ul1 + ul2); 37 | /* { dg-output "res: 2147483647, 2147483647" } */ 38 | CHECK(res == 2147483647L); 39 | CHECK(ul1 + ul2 == 2147483647L); 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/strlen.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check strlen function call. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static unsigned int ABI_ATTR my_strlen(char *s) 11 | { 12 | return (unsigned int) (strlen(s)); 13 | } 14 | 15 | int main (void) 16 | { 17 | ffi_cif cif; 18 | ffi_type *args[MAX_ARGS]; 19 | void *values[MAX_ARGS]; 20 | ffi_arg rint; 21 | char *s; 22 | 23 | args[0] = &ffi_type_pointer; 24 | values[0] = (void*) &s; 25 | 26 | /* Initialize the cif */ 27 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 28 | &ffi_type_uint, args) == FFI_OK); 29 | 30 | s = "a"; 31 | ffi_call(&cif, FFI_FN(my_strlen), &rint, values); 32 | CHECK(rint == 1); 33 | 34 | s = "1234567"; 35 | ffi_call(&cif, FFI_FN(my_strlen), &rint, values); 36 | CHECK(rint == 7); 37 | 38 | s = "1234567890123456789012345"; 39 | ffi_call(&cif, FFI_FN(my_strlen), &rint, values); 40 | CHECK(rint == 25); 41 | 42 | exit (0); 43 | } 44 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/strlen2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check strlen function call with additional arguments. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static int ABI_ATTR my_f(char *s, float a) 12 | { 13 | return (int) strlen(s) + (int) a; 14 | } 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[MAX_ARGS]; 20 | void *values[MAX_ARGS]; 21 | ffi_arg rint; 22 | char *s; 23 | float v2; 24 | args[0] = &ffi_type_pointer; 25 | args[1] = &ffi_type_float; 26 | values[0] = (void*) &s; 27 | values[1] = (void*) &v2; 28 | 29 | /* Initialize the cif */ 30 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, 31 | &ffi_type_sint, args) == FFI_OK); 32 | 33 | s = "a"; 34 | v2 = 0.0; 35 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 36 | CHECK(rint == 1); 37 | 38 | s = "1234567"; 39 | v2 = -1.0; 40 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 41 | CHECK(rint == 6); 42 | 43 | s = "1234567890123456789012345"; 44 | v2 = 1.0; 45 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 46 | CHECK(rint == 26); 47 | 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/strlen3.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check strlen function call with additional arguments. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static int ABI_ATTR my_f(float a, char *s) 12 | { 13 | return (int) strlen(s) + (int) a; 14 | } 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[MAX_ARGS]; 20 | void *values[MAX_ARGS]; 21 | ffi_arg rint; 22 | char *s; 23 | float v2; 24 | args[1] = &ffi_type_pointer; 25 | args[0] = &ffi_type_float; 26 | values[1] = (void*) &s; 27 | values[0] = (void*) &v2; 28 | 29 | /* Initialize the cif */ 30 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, 31 | &ffi_type_sint, args) == FFI_OK); 32 | 33 | s = "a"; 34 | v2 = 0.0; 35 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 36 | CHECK(rint == 1); 37 | 38 | s = "1234567"; 39 | v2 = -1.0; 40 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 41 | CHECK(rint == 6); 42 | 43 | s = "1234567890123456789012345"; 44 | v2 = 1.0; 45 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 46 | CHECK(rint == 26); 47 | 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.call/struct10.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Sergei Trofimovich 6 | 7 | The test originally discovered in ruby's bindings 8 | for ffi in https://bugs.gentoo.org/634190 */ 9 | 10 | /* { dg-do run } */ 11 | #include "ffitest.h" 12 | 13 | struct s { 14 | int s32; 15 | float f32; 16 | signed char s8; 17 | }; 18 | 19 | struct s ABI_ATTR make_s(void) { 20 | struct s r; 21 | r.s32 = 0x1234; 22 | r.f32 = 7.0; 23 | r.s8 = 0x78; 24 | return r; 25 | } 26 | 27 | int main() { 28 | ffi_cif cif; 29 | struct s r; 30 | ffi_type rtype; 31 | ffi_type* s_fields[] = { 32 | &ffi_type_sint, 33 | &ffi_type_float, 34 | &ffi_type_schar, 35 | NULL, 36 | }; 37 | 38 | rtype.size = 0; 39 | rtype.alignment = 0, 40 | rtype.type = FFI_TYPE_STRUCT, 41 | rtype.elements = s_fields, 42 | 43 | r.s32 = 0xbad; 44 | r.f32 = 999.999; 45 | r.s8 = 0x51; 46 | 47 | // Here we emulate the following call: 48 | //r = make_s(); 49 | 50 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &rtype, NULL) == FFI_OK); 51 | ffi_call(&cif, FFI_FN(make_s), &r, NULL); 52 | 53 | CHECK(r.s32 == 0x1234); 54 | CHECK(r.f32 == 7.0); 55 | CHECK(r.s8 == 0x78); 56 | exit(0); 57 | } 58 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.closures/cls_double.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_double_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(double *)resp = *(double *)args[0]; 14 | 15 | printf("%f: %f\n",*(double *)args[0], 16 | *(double *)resp); 17 | } 18 | typedef double (*cls_ret_double)(double); 19 | 20 | int main (void) 21 | { 22 | ffi_cif cif; 23 | void *code; 24 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 25 | ffi_type * cl_arg_types[2]; 26 | double res; 27 | 28 | cl_arg_types[0] = &ffi_type_double; 29 | cl_arg_types[1] = NULL; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 33 | &ffi_type_double, cl_arg_types) == FFI_OK); 34 | 35 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_double_fn, NULL, code) == FFI_OK); 36 | 37 | res = (*((cls_ret_double)code))(21474.789); 38 | /* { dg-output "21474.789000: 21474.789000" } */ 39 | printf("res: %.6f\n", res); 40 | /* { dg-output "\nres: 21474.789000" } */ 41 | 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.closures/err_bad_abi.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_prep_cif, ffi_prep_closure 2 | Purpose: Test error return for bad ABIs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/6/2007 */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static void 12 | dummy_fn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, 13 | void** args __UNUSED__, void* userdata __UNUSED__) 14 | {} 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | void *code; 20 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 21 | ffi_type* arg_types[1]; 22 | 23 | arg_types[0] = NULL; 24 | 25 | CHECK(ffi_prep_cif(&cif, 255, 0, &ffi_type_void, 26 | arg_types) == FFI_BAD_ABI); 27 | 28 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &ffi_type_void, 29 | arg_types) == FFI_OK); 30 | 31 | cif.abi= 255; 32 | 33 | CHECK(ffi_prep_closure_loc(pcl, &cif, dummy_fn, NULL, code) == FFI_BAD_ABI); 34 | 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.closures/ffitest.h: -------------------------------------------------------------------------------- 1 | #include "../libffi.call/ffitest.h" 2 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_align_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_align_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_align_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "cls_align_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_align_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "cls_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_struct_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check complex arguments in structs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_complex_struct.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_struct_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check complex arguments in structs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "cls_complex_struct.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check complex arguments in structs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_complex_struct.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_va_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test complex' passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_complex_va.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_va_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test complex' passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | /* Alpha splits _Complex into two arguments. It's illegal to pass 10 | float through varargs, so _Complex float goes badly. In sort of 11 | gets passed as _Complex double, but the compiler doesn't agree 12 | with itself on this issue. */ 13 | /* { dg-do run { xfail alpha*-*-* } } */ 14 | 15 | #include "complex_defs_float.inc" 16 | #include "cls_complex_va.inc" 17 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test complex' passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_complex_va.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/complex.exp: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003, 2006, 2009, 2010, 2014 Free Software Foundation, Inc. 2 | 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; see the file COPYING3. If not see 15 | # . 16 | 17 | dg-init 18 | libffi-init 19 | 20 | global srcdir subdir 21 | 22 | set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.{c,cc}]] 23 | 24 | if { [libffi_feature_test "#ifdef FFI_TARGET_HAS_COMPLEX_TYPE"] } { 25 | run-many-tests $tlist "" 26 | } else { 27 | foreach test $tlist { 28 | unsupported "$test" 29 | } 30 | } 31 | 32 | dg-finish 33 | 34 | # Local Variables: 35 | # tcl-indent-level:4 36 | # End: 37 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/complex_defs_double.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | /* Complex base type. */ 3 | #define T_FFI_TYPE ffi_type_complex_double 4 | /* C type corresponding to the base type. */ 5 | #define T_C_TYPE double 6 | /* C cast for a value of type T_C_TYPE that is passed to printf. */ 7 | #define T_CONV 8 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/complex_defs_float.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | /* Complex base type. */ 3 | #define T_FFI_TYPE ffi_type_complex_float 4 | /* C type corresponding to the base type. */ 5 | #define T_C_TYPE float 6 | /* C cast for a value of type T_C_TYPE that is passed to printf. */ 7 | #define T_CONV (double) 8 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | /* Complex base type. */ 3 | #define T_FFI_TYPE ffi_type_complex_longdouble 4 | /* C type corresponding to the base type. */ 5 | #define T_C_TYPE long double 6 | /* C cast for a value of type T_C_TYPE that is passed to printf. */ 7 | #define T_CONV 8 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check complex types. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check complex types. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check complex types. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/ffitest.h: -------------------------------------------------------------------------------- 1 | #include "../libffi.call/ffitest.h" 2 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/many_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex, with many arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "many_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/many_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex, with many arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "many_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/many_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex, with many arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "many_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | static _Complex T_C_TYPE return_c(_Complex T_C_TYPE c) 6 | { 7 | printf ("%f,%fi\n", T_CONV creal (c), T_CONV cimag (c)); 8 | return 2 * c; 9 | } 10 | int main (void) 11 | { 12 | ffi_cif cif; 13 | ffi_type *args[MAX_ARGS]; 14 | void *values[MAX_ARGS]; 15 | _Complex T_C_TYPE c, rc, rc2; 16 | T_C_TYPE cr, ci; 17 | 18 | args[0] = &T_FFI_TYPE; 19 | values[0] = &c; 20 | 21 | /* Initialize the cif */ 22 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 23 | &T_FFI_TYPE, args) == FFI_OK); 24 | 25 | for (cr = -127.0; cr < 127; cr++) 26 | { 27 | ci = 1000.0 - cr; 28 | c = cr + ci * I; 29 | ffi_call(&cif, FFI_FN(return_c), &rc, values); 30 | rc2 = return_c(c); 31 | printf ("%f,%fi vs %f,%fi\n", 32 | T_CONV creal (rc), T_CONV cimag (rc), 33 | T_CONV creal (rc2), T_CONV cimag (rc2)); 34 | CHECK(rc == 2 * c); 35 | } 36 | exit(0); 37 | } 38 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex1.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | static _Complex T_C_TYPE return_c(_Complex T_C_TYPE c1, float fl2, unsigned int in3, _Complex T_C_TYPE c4) 6 | { 7 | return c1 + fl2 + in3 + c4; 8 | } 9 | int main (void) 10 | { 11 | ffi_cif cif; 12 | ffi_type *args[MAX_ARGS]; 13 | void *values[MAX_ARGS]; 14 | _Complex T_C_TYPE c1, c4, rc, rc2; 15 | float fl2; 16 | unsigned int in3; 17 | args[0] = &T_FFI_TYPE; 18 | args[1] = &ffi_type_float; 19 | args[2] = &ffi_type_uint; 20 | args[3] = &T_FFI_TYPE; 21 | values[0] = &c1; 22 | values[1] = &fl2; 23 | values[2] = &in3; 24 | values[3] = &c4; 25 | 26 | /* Initialize the cif */ 27 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 28 | &T_FFI_TYPE, args) == FFI_OK); 29 | c1 = 127.0 + 255.0 * I; 30 | fl2 = 128.0; 31 | in3 = 255; 32 | c4 = 512.7 + 1024.1 * I; 33 | 34 | ffi_call(&cif, FFI_FN(return_c), &rc, values); 35 | rc2 = return_c(c1, fl2, in3, c4); 36 | printf ("%f,%fi vs %f,%fi\n", 37 | T_CONV creal (rc), T_CONV cimag (rc), 38 | T_CONV creal (rc2), T_CONV cimag (rc2)); 39 | CHECK(rc == rc2); 40 | exit(0); 41 | } 42 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex1_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "return_complex1.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex1_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "return_complex1.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex1_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "return_complex1.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex2.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | _Complex T_C_TYPE 6 | return_c(_Complex T_C_TYPE c1, _Complex T_C_TYPE c2, 7 | unsigned int in3, _Complex T_C_TYPE c4) 8 | { 9 | volatile _Complex T_C_TYPE r = c1 + c2 + in3 + c4; 10 | return r; 11 | } 12 | 13 | int main (void) 14 | { 15 | ffi_cif cif; 16 | ffi_type *args[MAX_ARGS]; 17 | void *values[MAX_ARGS]; 18 | _Complex T_C_TYPE c1, c2, c4, rc, rc2; 19 | unsigned int in3; 20 | args[0] = &T_FFI_TYPE; 21 | args[1] = &T_FFI_TYPE; 22 | args[2] = &ffi_type_uint; 23 | args[3] = &T_FFI_TYPE; 24 | values[0] = &c1; 25 | values[1] = &c2; 26 | values[2] = &in3; 27 | values[3] = &c4; 28 | 29 | /* Initialize the cif */ 30 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 31 | &T_FFI_TYPE, args) == FFI_OK); 32 | c1 = 127.0 + 255.0 * I; 33 | c2 = 128.0 + 256.0; 34 | in3 = 255; 35 | c4 = 512.7 + 1024.1 * I; 36 | 37 | ffi_call(&cif, FFI_FN(return_c), &rc, values); 38 | rc2 = return_c(c1, c2, in3, c4); 39 | printf ("%f,%fi vs %f,%fi\n", 40 | T_CONV creal (rc), T_CONV cimag (rc), 41 | T_CONV creal (rc2), T_CONV cimag (rc2)); 42 | CHECK(rc == rc2); 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex2_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "return_complex2.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex2_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "return_complex2.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex2_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "return_complex2.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "return_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "return_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.complex/return_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "return_complex.inc" 11 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.go/aa-direct.c: -------------------------------------------------------------------------------- 1 | /* { dg-do run } */ 2 | 3 | #include "static-chain.h" 4 | 5 | #if defined(__GNUC__) && !defined(__clang__) && defined(STATIC_CHAIN_REG) 6 | 7 | #include "ffitest.h" 8 | 9 | /* Blatent assumption here that the prologue doesn't clobber the 10 | static chain for trivial functions. If this is not true, don't 11 | define STATIC_CHAIN_REG, and we'll test what we can via other tests. */ 12 | void *doit(void) 13 | { 14 | register void *chain __asm__(STATIC_CHAIN_REG); 15 | return chain; 16 | } 17 | 18 | int main() 19 | { 20 | ffi_cif cif; 21 | void *result; 22 | 23 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 0, &ffi_type_pointer, NULL) == FFI_OK); 24 | 25 | ffi_call_go(&cif, FFI_FN(doit), &result, NULL, &result); 26 | 27 | CHECK(result == &result); 28 | 29 | return 0; 30 | } 31 | 32 | #else /* UNSUPPORTED */ 33 | int main() { return 0; } 34 | #endif 35 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.go/closure1.c: -------------------------------------------------------------------------------- 1 | /* { dg-do run } */ 2 | 3 | #include "ffitest.h" 4 | 5 | void doit(ffi_cif *cif, void *rvalue, void **avalue, void *closure) 6 | { 7 | (void)cif; 8 | (void)avalue; 9 | *(void **)rvalue = closure; 10 | } 11 | 12 | typedef void * (*FN)(void); 13 | 14 | int main() 15 | { 16 | ffi_cif cif; 17 | ffi_go_closure cl; 18 | void *result; 19 | 20 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 0, &ffi_type_pointer, NULL) == FFI_OK); 21 | CHECK(ffi_prep_go_closure(&cl, &cif, doit) == FFI_OK); 22 | 23 | ffi_call_go(&cif, FFI_FN(*(FN *)&cl), &result, NULL, &cl); 24 | 25 | CHECK(result == &cl); 26 | 27 | exit(0); 28 | } 29 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.go/ffitest.h: -------------------------------------------------------------------------------- 1 | #include "../libffi.call/ffitest.h" 2 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.go/go.exp: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003, 2006, 2009, 2010, 2014 Free Software Foundation, Inc. 2 | 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; see the file COPYING3. If not see 15 | # . 16 | 17 | dg-init 18 | libffi-init 19 | 20 | global srcdir subdir 21 | 22 | set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.{c,cc}]] 23 | 24 | if { [libffi_feature_test "#ifdef FFI_GO_CLOSURES"] } { 25 | run-many-tests $tlist "" 26 | } else { 27 | foreach test $tlist { 28 | unsupported "$test" 29 | } 30 | } 31 | 32 | dg-finish 33 | 34 | # Local Variables: 35 | # tcl-indent-level:4 36 | # End: 37 | -------------------------------------------------------------------------------- /components/modules/libffi/testsuite/libffi.go/static-chain.h: -------------------------------------------------------------------------------- 1 | #ifdef __aarch64__ 2 | # define STATIC_CHAIN_REG "x18" 3 | #elif defined(__alpha__) 4 | # define STATIC_CHAIN_REG "$1" 5 | #elif defined(__arm__) 6 | # define STATIC_CHAIN_REG "ip" 7 | #elif defined(__sparc__) 8 | # if defined(__arch64__) || defined(__sparcv9) 9 | # define STATIC_CHAIN_REG "g5" 10 | # else 11 | # define STATIC_CHAIN_REG "g2" 12 | # endif 13 | #elif defined(__x86_64__) 14 | # define STATIC_CHAIN_REG "r10" 15 | #elif defined(__i386__) 16 | # ifndef ABI_NUM 17 | # define STATIC_CHAIN_REG "ecx" /* FFI_DEFAULT_ABI only */ 18 | # endif 19 | #endif 20 | -------------------------------------------------------------------------------- /components/modules/lua-cjson/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | # @file CMakeLists.txt 3 | # @brief 4 | #/ 5 | 6 | # MODULE_PATH 7 | set(MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | # MODULE_NAME 10 | get_filename_component(MODULE_NAME ${MODULE_PATH} NAME) 11 | 12 | # LIB_SRCS 13 | 14 | file(GLOB_RECURSE LIB_SRCS "${MODULE_PATH}/*.c") 15 | 16 | # LIB_PUBLIC_INC 17 | set(LIB_PUBLIC_INC ${MODULE_PATH}) 18 | 19 | 20 | ######################################## 21 | # Target Configure 22 | ######################################## 23 | add_library(${MODULE_NAME}) 24 | 25 | target_sources(${MODULE_NAME} 26 | PRIVATE 27 | ${LIB_SRCS} 28 | ) 29 | 30 | target_include_directories(${MODULE_NAME} 31 | PRIVATE 32 | ${LIB_PRIVATE_INC} 33 | 34 | PUBLIC 35 | ${LIB_PUBLIC_INC} 36 | ) 37 | 38 | 39 | 40 | ######################################## 41 | # Layer Configure 42 | ######################################## 43 | list(APPEND COMPONENT_LIBS ${MODULE_NAME}) 44 | set(COMPONENT_LIBS "${COMPONENT_LIBS}" PARENT_SCOPE) 45 | list(APPEND COMPONENT_PUBINC ${LIB_PUBLIC_INC}) 46 | set(COMPONENT_PUBINC "${COMPONENT_PUBINC}" PARENT_SCOPE) 47 | 48 | -------------------------------------------------------------------------------- /components/modules/lua-cjson/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2012 Mark Pulford 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /components/modules/lua-cjson/fpconv.h: -------------------------------------------------------------------------------- 1 | /* Lua CJSON floating point conversion routines */ 2 | 3 | /* Buffer required to store the largest string representation of a double. 4 | * 5 | * Longest double printed with %.14g is 21 characters long: 6 | * -1.7976931348623e+308 */ 7 | # define FPCONV_G_FMT_BUFSIZE 32 8 | #define LUAT_FLOATPOINT_SUPPORT 1 9 | 10 | #define inline 11 | 12 | // #ifdef USE_INTERNAL_FPCONV 13 | // static inline void fpconv_init() 14 | // { 15 | // /* Do nothing - not required */ 16 | // } 17 | // #else 18 | // extern inline void fpconv_init(); 19 | // #endif 20 | 21 | extern int fpconv_g_fmt(char*, double, int); 22 | extern int fpconv_f_fmt(char*, double, int); 23 | extern double fpconv_strtod(const char*, char**); 24 | 25 | /* vi:ai et sw=4 ts=4: 26 | */ 27 | -------------------------------------------------------------------------------- /components/modules/lua-mbedtls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | # @file CMakeLists.txt 3 | # @brief 4 | #/ 5 | 6 | # MODULE_PATH 7 | set(MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | # MODULE_NAME 10 | get_filename_component(MODULE_NAME ${MODULE_PATH} NAME) 11 | 12 | # LIB_SRCS 13 | 14 | file(GLOB_RECURSE LIB_SRCS "${MODULE_PATH}/src/*.c") 15 | 16 | # LIB_PUBLIC_INC 17 | set(LIB_PUBLIC_INC ${MODULE_PATH}/include) 18 | 19 | 20 | ######################################## 21 | # Target Configure 22 | ######################################## 23 | add_library(${MODULE_NAME}) 24 | 25 | target_sources(${MODULE_NAME} 26 | PRIVATE 27 | ${LIB_SRCS} 28 | ) 29 | 30 | target_include_directories(${MODULE_NAME} 31 | PRIVATE 32 | ${LIB_PRIVATE_INC} 33 | 34 | PUBLIC 35 | ${LIB_PUBLIC_INC} 36 | ) 37 | 38 | 39 | 40 | ######################################## 41 | # Layer Configure 42 | ######################################## 43 | list(APPEND COMPONENT_LIBS ${MODULE_NAME}) 44 | set(COMPONENT_LIBS "${COMPONENT_LIBS}" PARENT_SCOPE) 45 | list(APPEND COMPONENT_PUBINC ${LIB_PUBLIC_INC}) 46 | set(COMPONENT_PUBINC "${COMPONENT_PUBINC}" PARENT_SCOPE) 47 | 48 | -------------------------------------------------------------------------------- /components/modules/lua-mbedtls/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2020-2022 Arseny Vakhrushev 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /components/modules/lua-mbedtls/VERSION: -------------------------------------------------------------------------------- 1 | Current: 0.2.2 2 | Release: 0.2.2 3 | -------------------------------------------------------------------------------- /components/modules/lua-mbedtls/doc/base64.md: -------------------------------------------------------------------------------- 1 | Base64 2 | ====== 3 | 4 | ```Lua 5 | local base64 = require 'mbedtls.base64' 6 | ``` 7 | 8 | ### base64.encode(data, [pos], [len]) 9 | Encodes `data` into a Base64 representation. Optional `pos` marks the beginning of data (default is 1). Optional `len` marks the size of data (default is `#data - pos + 1`). 10 | 11 | ### base64.decode(data, [pos], [len]) 12 | Decodes Base64 `data`. Optional `pos` marks the beginning of data (default is 1). Optional `len` marks the size of data (default is `#data - pos + 1`). 13 | -------------------------------------------------------------------------------- /components/modules/lua-mbedtls/doc/md.md: -------------------------------------------------------------------------------- 1 | Message Digest 2 | ============== 3 | 4 | ```Lua 5 | local md = require 'mbedtls.md' 6 | ``` 7 | 8 | ### md.hash(type, data, [raw]) 9 | Returns a message digest of `type` for `data` as a hexadecimal (or raw if `raw = true`) string. 10 | 11 | ### md.hmac(type, key, data, [raw]) 12 | Returns an HMAC of `type` for `key` and `data` as a hexadecimal (or raw if `raw = true`) string. 13 | 14 | The `type` argument (a string) can be one of the following: 15 | - `MD2` 16 | - `MD4` 17 | - `MD5` 18 | - `SHA1` 19 | - `SHA224` 20 | - `SHA256` 21 | - `SHA384` 22 | - `SHA512` 23 | - `RIPEMD160` 24 | -------------------------------------------------------------------------------- /components/modules/lua-mbedtls/rockspec/lua-mbedtls-git-1.rockspec: -------------------------------------------------------------------------------- 1 | package = 'lua-mbedtls' 2 | version = 'git-1' 3 | source = { 4 | url = 'git://github.com/neoxic/lua-mbedtls.git', 5 | } 6 | description = { 7 | summary = 'Mbed TLS module for Lua', 8 | detailed = [[ 9 | lua-mbedtls adds support for Mbed TLS in Lua: 10 | * SSL/TLS communication + cookie API. 11 | * Message digest and HMAC. 12 | * Base64 encoding/decoding. 13 | ]], 14 | license = 'MIT', 15 | homepage = 'https://github.com/neoxic/lua-mbedtls', 16 | maintainer = 'Arseny Vakhrushev ', 17 | } 18 | dependencies = { 19 | 'lua >= 5.1', 20 | } 21 | external_dependencies = { 22 | MBEDTLS = { 23 | header = 'mbedtls/version.h', 24 | library = 'mbedtls', 25 | }, 26 | } 27 | build = { 28 | type = 'builtin', 29 | modules = { 30 | mbedtls = { 31 | sources = { 32 | 'src/base64.c', 33 | 'src/main.c', 34 | 'src/md.c', 35 | 'src/ssl.c', 36 | }, 37 | incdirs = '$(MBEDTLS_INCDIR)', 38 | libdirs = '$(MBEDTLS_LIBDIR)', 39 | libraries = {'mbedtls', 'mbedcrypto', 'mbedx509'}, 40 | }, 41 | }, 42 | } 43 | -------------------------------------------------------------------------------- /components/modules/lua-socket/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | charset = utf-8 8 | 9 | [{*.lua,*.rockspec,.luacheckrc}] 10 | indent_style = space 11 | indent_size = 4 12 | 13 | [Makefile] 14 | indent_style = tab 15 | indent_size = 4 16 | 17 | [*.html] 18 | indent_style = space 19 | indent_size = 4 20 | 21 | [*.{c,h}] 22 | indent_style = space 23 | indent_size = 4 24 | -------------------------------------------------------------------------------- /components/modules/lua-socket/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.so.* 4 | *.obj 5 | *.lib 6 | *.dll* 7 | *.user 8 | *.sdf 9 | Debug 10 | Release 11 | *.manifest 12 | *.swp 13 | *.suo 14 | x64 15 | 16 | -------------------------------------------------------------------------------- /components/modules/lua-socket/.luacheckrc: -------------------------------------------------------------------------------- 1 | unused_args = false 2 | redefined = false 3 | max_line_length = false 4 | 5 | not_globals = { 6 | "string.len", 7 | "table.getn", 8 | } 9 | 10 | include_files = { 11 | "**/*.lua", 12 | "**/*.rockspec", 13 | ".busted", 14 | ".luacheckrc", 15 | } 16 | 17 | exclude_files = { 18 | "etc/*.lua", 19 | "etc/**/*.lua", 20 | "test/*.lua", 21 | "test/**/*.lua", 22 | "samples/*.lua", 23 | "samples/**/*.lua", 24 | "gem/*.lua", 25 | "gem/**/*.lua", 26 | -- GH Actions Lua Environment 27 | ".lua", 28 | ".luarocks", 29 | ".install", 30 | } 31 | 32 | -------------------------------------------------------------------------------- /components/modules/lua-socket/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2004-2022 Diego Nehab 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /components/modules/lua-socket/README.md: -------------------------------------------------------------------------------- 1 | # LuaSocket 2 | 3 | 4 | [![Build](https://img.shields.io/github/workflow/status/lunarmodules/luasocket/Build?label=Build=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Build) 5 | [![Luacheck](https://img.shields.io/github/workflow/status/lunarmodules/luasocket/Luacheck?label=Luacheck&logo=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Luacheck) 6 | [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/lunarmodules/luasocket?label=Tag&logo=GitHub)](https://github.com/lunarmodules/luasocket/releases) 7 | [![Luarocks](https://img.shields.io/luarocks/v/lunarmodules/luasocket?label=Luarocks&logo=Lua)](https://luarocks.org/modules/lunarmodules/luasocket) 8 | 9 | LuaSocket is a Lua extension library composed of two parts: 10 | 11 | 1. a set of C modules that provide support for the TCP and UDP transport layers, and 12 | 2. a set of Lua modules that provide functions commonly needed by applications that deal with the Internet. 13 | -------------------------------------------------------------------------------- /components/modules/lua-socket/TODO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/modules/lua-socket/TODO -------------------------------------------------------------------------------- /components/modules/lua-socket/WISH: -------------------------------------------------------------------------------- 1 | ... as an l-value to get all results of a function call? 2 | at least ...[i] and #... 3 | extend to full tuples? 4 | 5 | __and __or __not metamethods 6 | 7 | lua_tostring, lua_tonumber, lua_touseradta etc push values in stack 8 | __tostring,__tonumber, __touserdata metamethods are checked 9 | and expected to push an object of correct type on stack 10 | 11 | lua_rawtostring, lua_rawtonumber, lua_rawtouserdata don't 12 | push anything on stack, return data of appropriate type, 13 | skip metamethods and throw error if object not of exact type 14 | 15 | package.findfile exported 16 | module not polluting the global namespace 17 | 18 | coxpcall with a coroutine pool for efficiency (reusing coroutines) 19 | 20 | exception mechanism formalized? just like the package system was. 21 | 22 | a nice bitlib in the core 23 | -------------------------------------------------------------------------------- /components/modules/lua-socket/docs/lua05.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/modules/lua-socket/docs/lua05.ppt -------------------------------------------------------------------------------- /components/modules/lua-socket/docs/luasocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/modules/lua-socket/docs/luasocket.png -------------------------------------------------------------------------------- /components/modules/lua-socket/docs/reference.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 1em; 3 | margin-right: 1em; 4 | font-family: "Verdana", sans-serif; 5 | background: #ffffff; 6 | } 7 | 8 | tt { 9 | font-family: "Andale Mono", monospace; 10 | } 11 | 12 | h1, h2, h3, h4 { margin-left: 0em; } 13 | 14 | 15 | h3 { padding-top: 1em; } 16 | 17 | p { margin-left: 1em; } 18 | 19 | p.name { 20 | font-family: "Andale Mono", monospace; 21 | padding-top: 1em; 22 | margin-left: 0em; 23 | } 24 | 25 | a[href] { color: #00007f; } 26 | 27 | blockquote { margin-left: 3em; } 28 | 29 | pre.example { 30 | background: #ccc; 31 | padding: 1em; 32 | margin-left: 1em; 33 | font-family: "Andale Mono", monospace; 34 | font-size: small; 35 | } 36 | 37 | hr { 38 | margin-left: 0em; 39 | background: #00007f; 40 | border: 0px; 41 | height: 1px; 42 | } 43 | 44 | ul { list-style-type: disc; } 45 | 46 | table.index { border: 1px #00007f; } 47 | table.index td { text-align: left; vertical-align: top; } 48 | table.index ul { padding-top: 0em; margin-top: 0em; } 49 | 50 | h1:first-letter, 51 | h2:first-letter, 52 | h2:first-letter, 53 | h3:first-letter { color: #00007f; } 54 | 55 | div.header, div.footer { margin-left: 0em; } 56 | -------------------------------------------------------------------------------- /components/modules/lua-socket/etc/b64.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Little program to convert to and from Base64 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local ltn12 = require("ltn12") 7 | local mime = require("mime") 8 | local source = ltn12.source.file(io.stdin) 9 | local sink = ltn12.sink.file(io.stdout) 10 | local convert 11 | if arg and arg[1] == '-d' then 12 | convert = mime.decode("base64") 13 | else 14 | local base64 = mime.encode("base64") 15 | local wrap = mime.wrap() 16 | convert = ltn12.filter.chain(base64, wrap) 17 | end 18 | sink = ltn12.sink.chain(convert, sink) 19 | ltn12.pump.all(source, sink) 20 | -------------------------------------------------------------------------------- /components/modules/lua-socket/etc/check-memory.lua: -------------------------------------------------------------------------------- 1 | function load(s) 2 | collectgarbage() 3 | local a = gcinfo() 4 | _G[s] = require(s) 5 | collectgarbage() 6 | local b = gcinfo() 7 | print(s .. ":\t " .. (b-a) .. "k") 8 | end 9 | 10 | load("socket.url") 11 | load("ltn12") 12 | load("socket") 13 | load("mime") 14 | load("socket.tp") 15 | load("socket.smtp") 16 | load("socket.http") 17 | load("socket.ftp") 18 | -------------------------------------------------------------------------------- /components/modules/lua-socket/etc/eol.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Little program to adjust end of line markers. 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local mime = require("mime") 7 | local ltn12 = require("ltn12") 8 | local marker = '\n' 9 | if arg and arg[1] == '-d' then marker = '\r\n' end 10 | local filter = mime.normalize(marker) 11 | local source = ltn12.source.chain(ltn12.source.file(io.stdin), filter) 12 | local sink = ltn12.sink.file(io.stdout) 13 | ltn12.pump.all(source, sink) 14 | -------------------------------------------------------------------------------- /components/modules/lua-socket/etc/links: -------------------------------------------------------------------------------- 1 | bla 2 | bla 3 | bla 4 | bla 5 | bla 6 | bla 7 | bla 8 | bla 9 | bla 10 | bla 11 | bla 12 | bla 13 | bla 14 | bla 15 | bla 16 | bla 17 | bla 18 | -------------------------------------------------------------------------------- /components/modules/lua-socket/etc/qp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Little program to convert to and from Quoted-Printable 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local ltn12 = require("ltn12") 7 | local mime = require("mime") 8 | local convert 9 | arg = arg or {} 10 | local mode = arg and arg[1] or "-et" 11 | if mode == "-et" then 12 | local normalize = mime.normalize() 13 | local qp = mime.encode("quoted-printable") 14 | local wrap = mime.wrap("quoted-printable") 15 | convert = ltn12.filter.chain(normalize, qp, wrap) 16 | elseif mode == "-eb" then 17 | local qp = mime.encode("quoted-printable", "binary") 18 | local wrap = mime.wrap("quoted-printable") 19 | convert = ltn12.filter.chain(qp, wrap) 20 | else convert = mime.decode("quoted-printable") end 21 | local source = ltn12.source.chain(ltn12.source.file(io.stdin), convert) 22 | local sink = ltn12.sink.file(io.stdout) 23 | ltn12.pump.all(source, sink) 24 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex1.lua: -------------------------------------------------------------------------------- 1 | local CRLF = "\013\010" 2 | local input = source.chain(source.file(io.stdin), normalize(CRLF)) 3 | local output = sink.file(io.stdout) 4 | pump.all(input, output) 5 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex10.lua: -------------------------------------------------------------------------------- 1 | function pump.step(src, snk) 2 | local chunk, src_err = src() 3 | local ret, snk_err = snk(chunk, src_err) 4 | if chunk and ret then return 1 5 | else return nil, src_err or snk_err end 6 | end 7 | 8 | function pump.all(src, snk, step) 9 | step = step or pump.step 10 | while true do 11 | local ret, err = step(src, snk) 12 | if not ret then 13 | if err then return nil, err 14 | else return 1 end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex11.lua: -------------------------------------------------------------------------------- 1 | local input = source.chain( 2 | source.file(io.open("input.bin", "rb")), 3 | encode("base64")) 4 | local output = sink.chain( 5 | wrap(76), 6 | sink.file(io.open("output.b64", "w"))) 7 | pump.all(input, output) 8 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex12.lua: -------------------------------------------------------------------------------- 1 | local smtp = require"socket.smtp" 2 | local mime = require"mime" 3 | local ltn12 = require"ltn12" 4 | 5 | CRLF = "\013\010" 6 | 7 | local message = smtp.message{ 8 | headers = { 9 | from = "Sicrano ", 10 | to = "Fulano ", 11 | subject = "A message with an attachment"}, 12 | body = { 13 | preamble = "Hope you can see the attachment" .. CRLF, 14 | [1] = { 15 | body = "Here is our logo" .. CRLF}, 16 | [2] = { 17 | headers = { 18 | ["content-type"] = 'image/png; name="luasocket.png"', 19 | ["content-disposition"] = 20 | 'attachment; filename="luasocket.png"', 21 | ["content-description"] = 'LuaSocket logo', 22 | ["content-transfer-encoding"] = "BASE64"}, 23 | body = ltn12.source.chain( 24 | ltn12.source.file(io.open("luasocket.png", "rb")), 25 | ltn12.filter.chain( 26 | mime.encode("base64"), 27 | mime.wrap()))}}} 28 | 29 | assert(smtp.send{ 30 | rcpt = "", 31 | from = "", 32 | server = "localhost", 33 | port = 2525, 34 | source = message}) 35 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex2.lua: -------------------------------------------------------------------------------- 1 | function filter.cycle(lowlevel, context, extra) 2 | return function(chunk) 3 | local ret 4 | ret, context = lowlevel(context, chunk, extra) 5 | return ret 6 | end 7 | end 8 | 9 | function normalize(marker) 10 | return filter.cycle(eol, 0, marker) 11 | end 12 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex3.lua: -------------------------------------------------------------------------------- 1 | local function chainpair(f1, f2) 2 | return function(chunk) 3 | local ret = f2(f1(chunk)) 4 | if chunk then return ret 5 | else return (ret or "") .. (f2() or "") end 6 | end 7 | end 8 | 9 | function filter.chain(...) 10 | local f = select(1, ...) 11 | for i = 2, select('#', ...) do 12 | f = chainpair(f, select(i, ...)) 13 | end 14 | return f 15 | end 16 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex4.lua: -------------------------------------------------------------------------------- 1 | local qp = filter.chain(normalize(CRLF), encode("quoted-printable"), 2 | wrap("quoted-printable")) 3 | local input = source.chain(source.file(io.stdin), qp) 4 | local output = sink.file(io.stdout) 5 | pump.all(input, output) 6 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex5.lua: -------------------------------------------------------------------------------- 1 | function source.empty(err) 2 | return function() 3 | return nil, err 4 | end 5 | end 6 | 7 | function source.file(handle, io_err) 8 | if handle then 9 | return function() 10 | local chunk = handle:read(20) 11 | if not chunk then handle:close() end 12 | return chunk 13 | end 14 | else return source.empty(io_err or "unable to open file") end 15 | end 16 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex6.lua: -------------------------------------------------------------------------------- 1 | function source.chain(src, f) 2 | return function() 3 | if not src then 4 | return nil 5 | end 6 | local chunk, err = src() 7 | if not chunk then 8 | src = nil 9 | return f(nil) 10 | else 11 | return f(chunk) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex7.lua: -------------------------------------------------------------------------------- 1 | function sink.table(t) 2 | t = t or {} 3 | local f = function(chunk, err) 4 | if chunk then table.insert(t, chunk) end 5 | return 1 6 | end 7 | return f, t 8 | end 9 | 10 | local function null() 11 | return 1 12 | end 13 | 14 | function sink.null() 15 | return null 16 | end 17 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex8.lua: -------------------------------------------------------------------------------- 1 | local input = source.file(io.stdin) 2 | local output, t = sink.table() 3 | output = sink.chain(normalize(CRLF), output) 4 | pump.all(input, output) 5 | io.write(table.concat(t)) 6 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/ex9.lua: -------------------------------------------------------------------------------- 1 | for chunk in source.file(io.stdin) do 2 | io.write(chunk) 3 | end 4 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/input.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/modules/lua-socket/gem/input.bin -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/luasocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/modules/lua-socket/gem/luasocket.png -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/makefile: -------------------------------------------------------------------------------- 1 | ltn012.pdf: ltn012.ps 2 | ./myps2pdf ltn012.ps 3 | 4 | ltn012.ps: ltn012.dvi 5 | dvips -G0 -t letter -o ltn012.ps ltn012.dvi 6 | 7 | ltn012.dvi: ltn012.tex 8 | latex ltn012 9 | 10 | clean: 11 | rm -f *~ *.log *.aux *.bbl *.blg ltn012.pdf ltn012.ps ltn012.dvi ltn012.lof ltn012.toc ltn012.lot 12 | 13 | pdf: ltn012.pdf 14 | open ltn012.pdf 15 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t1.lua: -------------------------------------------------------------------------------- 1 | source = {} 2 | sink = {} 3 | pump = {} 4 | filter = {} 5 | 6 | -- source.chain 7 | dofile("ex6.lua") 8 | 9 | -- source.file 10 | dofile("ex5.lua") 11 | 12 | -- normalize 13 | require"gem" 14 | eol = gem.eol 15 | dofile("ex2.lua") 16 | 17 | -- sink.file 18 | require"ltn12" 19 | sink.file = ltn12.sink.file 20 | 21 | -- pump.all 22 | dofile("ex10.lua") 23 | 24 | -- run test 25 | dofile("ex1.lua") 26 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t1lf.txt: -------------------------------------------------------------------------------- 1 | this is a test file 2 | it should have been saved as lf eol 3 | but t1.lua will convert it to crlf eol 4 | otherwise it is broken! 5 | 6 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t2.lua: -------------------------------------------------------------------------------- 1 | source = {} 2 | sink = {} 3 | pump = {} 4 | filter = {} 5 | 6 | -- filter.chain 7 | dofile("ex3.lua") 8 | 9 | -- normalize 10 | require"gem" 11 | eol = gem.eol 12 | dofile("ex2.lua") 13 | 14 | -- encode 15 | require"mime" 16 | encode = mime.encode 17 | 18 | -- wrap 19 | wrap = mime.wrap 20 | 21 | -- source.chain 22 | dofile("ex6.lua") 23 | 24 | -- source.file 25 | dofile("ex5.lua") 26 | 27 | -- sink.file 28 | require"ltn12" 29 | sink.file = ltn12.sink.file 30 | 31 | -- pump.all 32 | dofile("ex10.lua") 33 | 34 | -- run test 35 | CRLF = "\013\010" 36 | dofile("ex4.lua") 37 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/modules/lua-socket/gem/t2.txt -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t2gt.qp: -------------------------------------------------------------------------------- 1 | esse =E9 um texto com acentos 2 | quoted-printable tem que quebrar linhas longas, com mais que 76 linhas de t= 3 | exto 4 | fora que as quebras de linhas t=EAm que ser normalizadas 5 | vamos ver o que d=E1 isso aqui 6 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t3.lua: -------------------------------------------------------------------------------- 1 | source = {} 2 | sink = {} 3 | pump = {} 4 | filter = {} 5 | 6 | -- source.file 7 | dofile("ex5.lua") 8 | 9 | -- sink.table 10 | dofile("ex7.lua") 11 | 12 | -- sink.chain 13 | require"ltn12" 14 | sink.chain = ltn12.sink.chain 15 | 16 | -- normalize 17 | require"gem" 18 | eol = gem.eol 19 | dofile("ex2.lua") 20 | 21 | -- pump.all 22 | dofile("ex10.lua") 23 | 24 | -- run test 25 | dofile("ex8.lua") 26 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t4.lua: -------------------------------------------------------------------------------- 1 | source = {} 2 | sink = {} 3 | pump = {} 4 | filter = {} 5 | 6 | -- source.file 7 | dofile("ex5.lua") 8 | 9 | -- run test 10 | dofile("ex9.lua") 11 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/t5.lua: -------------------------------------------------------------------------------- 1 | source = {} 2 | sink = {} 3 | pump = {} 4 | filter = {} 5 | 6 | -- source.chain 7 | dofile("ex6.lua") 8 | 9 | -- source.file 10 | dofile("ex5.lua") 11 | 12 | -- encode 13 | require"mime" 14 | encode = mime.encode 15 | 16 | -- sink.chain 17 | require"ltn12" 18 | sink.chain = ltn12.sink.chain 19 | 20 | -- wrap 21 | wrap = mime.wrap 22 | 23 | -- sink.file 24 | sink.file = ltn12.sink.file 25 | 26 | -- pump.all 27 | dofile("ex10.lua") 28 | 29 | -- run test 30 | dofile("ex11.lua") 31 | -------------------------------------------------------------------------------- /components/modules/lua-socket/gem/test.lua: -------------------------------------------------------------------------------- 1 | function readfile(n) 2 | local f = io.open(n, "rb") 3 | local s = f:read("*a") 4 | f:close() 5 | return s 6 | end 7 | 8 | lf = readfile("t1lf.txt") 9 | os.remove("t1crlf.txt") 10 | os.execute("lua t1.lua < t1lf.txt > t1crlf.txt") 11 | crlf = readfile("t1crlf.txt") 12 | assert(crlf == string.gsub(lf, "\010", "\013\010"), "broken") 13 | 14 | gt = readfile("t2gt.qp") 15 | os.remove("t2.qp") 16 | os.execute("lua t2.lua < t2.txt > t2.qp") 17 | t2 = readfile("t2.qp") 18 | assert(gt == t2, "broken") 19 | 20 | os.remove("t1crlf.txt") 21 | os.execute("lua t3.lua < t1lf.txt > t1crlf.txt") 22 | crlf = readfile("t1crlf.txt") 23 | assert(crlf == string.gsub(lf, "\010", "\013\010"), "broken") 24 | 25 | t = readfile("test.lua") 26 | os.execute("lua t4.lua < test.lua > t") 27 | t2 = readfile("t") 28 | assert(t == t2, "broken") 29 | 30 | os.remove("output.b64") 31 | gt = readfile("gt.b64") 32 | os.execute("lua t5.lua") 33 | t5 = readfile("output.b64") 34 | assert(gt == t5, "failed") 35 | 36 | print("1 2 5 6 10 passed") 37 | print("2 3 4 5 6 10 passed") 38 | print("2 5 6 7 8 10 passed") 39 | print("5 9 passed") 40 | print("5 6 10 11 passed") 41 | 42 | os.remove("t") 43 | os.remove("t2.qp") 44 | os.remove("t1crlf.txt") 45 | os.remove("t11.b64") 46 | os.remove("output.b64") 47 | -------------------------------------------------------------------------------- /components/modules/lua-socket/linux.cmd: -------------------------------------------------------------------------------- 1 | make PLAT=linux DEBUG=DEBUG LUAINC_linux_base=/home/diego/build/ubuntu/include LUAPREFIX_linux=/home/diego/build/ubuntu 2 | -------------------------------------------------------------------------------- /components/modules/lua-socket/macosx.cmd: -------------------------------------------------------------------------------- 1 | make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/$USER/build/macosx/include LUAPREFIX_macosx=/Users/$USER/build/macosx install-both 2 | -------------------------------------------------------------------------------- /components/modules/lua-socket/mingw.cmd: -------------------------------------------------------------------------------- 1 | make PLAT=mingw LUAINC_mingw_base=/home/diego/build/mingw/include LUALIB_mingw_base=/home/diego/build/mingw/bin LUAPREFIX_mingw=/home/diego/build/mingw/bin DEBUG=DEBUG install-both 2 | -------------------------------------------------------------------------------- /components/modules/lua-socket/samples/daytimeclnt.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- UDP sample: daytime protocol client 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local socket = require"socket" 7 | host = host or "127.0.0.1" 8 | port = port or 13 9 | if arg then 10 | host = arg[1] or host 11 | port = arg[2] or port 12 | end 13 | host = socket.dns.toip(host) 14 | udp = socket.udp() 15 | print("Using host '" ..host.. "' and port " ..port.. "...") 16 | udp:setpeername(host, port) 17 | udp:settimeout(3) 18 | sent, err = udp:send("anything") 19 | if err then print(err) os.exit() end 20 | dgram, err = udp:receive() 21 | if not dgram then print(err) os.exit() end 22 | io.write(dgram) 23 | -------------------------------------------------------------------------------- /components/modules/lua-socket/samples/echoclnt.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- UDP sample: echo protocol client 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local socket = require("socket") 7 | host = host or "localhost" 8 | port = port or 7 9 | if arg then 10 | host = arg[1] or host 11 | port = arg[2] or port 12 | end 13 | host = socket.dns.toip(host) 14 | udp = assert(socket.udp()) 15 | assert(udp:setpeername(host, port)) 16 | print("Using remote host '" ..host.. "' and port " .. port .. "...") 17 | while 1 do 18 | line = io.read() 19 | if not line or line == "" then os.exit() end 20 | assert(udp:send(line)) 21 | dgram = assert(udp:receive()) 22 | print(dgram) 23 | end 24 | -------------------------------------------------------------------------------- /components/modules/lua-socket/samples/echosrvr.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- UDP sample: echo protocol server 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local socket = require("socket") 7 | host = host or "127.0.0.1" 8 | port = port or 7 9 | if arg then 10 | host = arg[1] or host 11 | port = arg[2] or port 12 | end 13 | print("Binding to host '" ..host.. "' and port " ..port.. "...") 14 | udp = assert(socket.udp()) 15 | assert(udp:setsockname(host, port)) 16 | assert(udp:settimeout(5)) 17 | ip, port = udp:getsockname() 18 | assert(ip, port) 19 | print("Waiting packets on " .. ip .. ":" .. port .. "...") 20 | while 1 do 21 | dgram, ip, port = udp:receivefrom() 22 | if dgram then 23 | print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port) 24 | udp:sendto(dgram, ip, port) 25 | else 26 | print(ip) 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /components/modules/lua-socket/samples/listener.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- TCP sample: Little program to dump lines received at a given port 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local socket = require("socket") 7 | host = host or "*" 8 | port = port or 8080 9 | if arg then 10 | host = arg[1] or host 11 | port = arg[2] or port 12 | end 13 | print("Binding to host '" ..host.. "' and port " ..port.. "...") 14 | s = assert(socket.bind(host, port)) 15 | i, p = s:getsockname() 16 | assert(i, p) 17 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") 18 | c = assert(s:accept()) 19 | print("Connected. Here is the stuff:") 20 | l, e = c:receive() 21 | while not e do 22 | print(l) 23 | l, e = c:receive() 24 | end 25 | print(e) 26 | -------------------------------------------------------------------------------- /components/modules/lua-socket/samples/mclisten.lua: -------------------------------------------------------------------------------- 1 | local socket = require"socket" 2 | local group = "225.0.0.37" 3 | local port = 12345 4 | local c = assert(socket.udp()) 5 | print(assert(c:setoption("reuseport", true))) 6 | print(assert(c:setsockname("*", port))) 7 | --print("loop:", c:getoption("ip-multicast-loop")) 8 | --print(assert(c:setoption("ip-multicast-loop", false))) 9 | --print("loop:", c:getoption("ip-multicast-loop")) 10 | --print("if:", c:getoption("ip-multicast-if")) 11 | --print(assert(c:setoption("ip-multicast-if", "127.0.0.1"))) 12 | --print("if:", c:getoption("ip-multicast-if")) 13 | --print(assert(c:setoption("ip-multicast-if", "10.0.1.4"))) 14 | --print("if:", c:getoption("ip-multicast-if")) 15 | print(assert(c:setoption("ip-add-membership", {multiaddr = group, interface = "*"}))) 16 | while 1 do 17 | print(c:receivefrom()) 18 | end 19 | -------------------------------------------------------------------------------- /components/modules/lua-socket/samples/mcsend.lua: -------------------------------------------------------------------------------- 1 | local socket = require"socket" 2 | local group = "225.0.0.37" 3 | local port = 12345 4 | local c = assert(socket.udp()) 5 | --print(assert(c:setoption("reuseport", true))) 6 | --print(assert(c:setsockname("*", port))) 7 | --print(assert(c:setoption("ip-multicast-loop", false))) 8 | --print(assert(c:setoption("ip-multicast-ttl", 4))) 9 | --print(assert(c:setoption("ip-multicast-if", "10.0.1.3"))) 10 | --print(assert(c:setoption("ip-add-membership", {multiaddr = group, interface = "*"}))) 11 | local i = 0 12 | while 1 do 13 | local message = string.format("hello all %d!", i) 14 | assert(c:sendto(message, group, port)) 15 | print("sent " .. message) 16 | socket.sleep(1) 17 | c:settimeout(0.5) 18 | print(c:receivefrom()) 19 | i = i + 1 20 | end 21 | -------------------------------------------------------------------------------- /components/modules/lua-socket/samples/talker.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- TCP sample: Little program to send text lines to a given host/port 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local socket = require("socket") 7 | host = host or "localhost" 8 | port = port or 8080 9 | if arg then 10 | host = arg[1] or host 11 | port = arg[2] or port 12 | end 13 | print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") 14 | c = assert(socket.connect(host, port)) 15 | print("Connected! Please type stuff (empty line to stop):") 16 | l = io.read() 17 | while l and l ~= "" and not e do 18 | assert(c:send(l .. "\n")) 19 | l = io.read() 20 | end 21 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPAT_H 2 | #define COMPAT_H 3 | 4 | #if LUA_VERSION_NUM==501 5 | 6 | #ifndef _WIN32 7 | #pragma GCC visibility push(hidden) 8 | #endif 9 | 10 | void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup); 11 | void *luasocket_testudata ( lua_State *L, int arg, const char *tname); 12 | 13 | #ifndef _WIN32 14 | #pragma GCC visibility pop 15 | #endif 16 | 17 | #define luaL_setfuncs luasocket_setfuncs 18 | #define luaL_testudata luasocket_testudata 19 | 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/io.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * Input/Output abstraction 3 | * LuaSocket toolkit 4 | \*=========================================================================*/ 5 | #include "luasocket.h" 6 | #include "io.h" 7 | 8 | /*-------------------------------------------------------------------------*\ 9 | * Initializes C structure 10 | \*-------------------------------------------------------------------------*/ 11 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { 12 | io->send = send; 13 | io->recv = recv; 14 | io->error = error; 15 | io->ctx = ctx; 16 | } 17 | 18 | /*-------------------------------------------------------------------------*\ 19 | * I/O error strings 20 | \*-------------------------------------------------------------------------*/ 21 | const char *io_strerror(int err) { 22 | switch (err) { 23 | case IO_DONE: return NULL; 24 | case IO_CLOSED: return "closed"; 25 | case IO_TIMEOUT: return "timeout"; 26 | case IO_UNSUPPORTED:return "unsupport"; 27 | default: return "unknown error"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef MIME_H 2 | #define MIME_H 3 | /*=========================================================================*\ 4 | * Core MIME support 5 | * LuaSocket toolkit 6 | * 7 | * This module provides functions to implement transfer content encodings 8 | * and formatting conforming to RFC 2045. It is used by mime.lua, which 9 | * provide a higher level interface to this functionality. 10 | \*=========================================================================*/ 11 | #include "luasocket.h" 12 | 13 | /*-------------------------------------------------------------------------*\ 14 | * Current MIME library version 15 | \*-------------------------------------------------------------------------*/ 16 | #define MIME_VERSION "MIME 1.0.3" 17 | #define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab" 18 | #define MIME_AUTHORS "Diego Nehab" 19 | 20 | LUASOCKET_API int luaopen_mime_core(lua_State *L); 21 | 22 | #endif /* MIME_H */ 23 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/select.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECT_H 2 | #define SELECT_H 3 | /*=========================================================================*\ 4 | * Select implementation 5 | * LuaSocket toolkit 6 | * 7 | * Each object that can be passed to the select function has to export 8 | * method getfd() which returns the descriptor to be passed to the 9 | * underlying select function. Another method, dirty(), should return 10 | * true if there is data ready for reading (required for buffered input). 11 | \*=========================================================================*/ 12 | 13 | #ifndef _WIN32 14 | #pragma GCC visibility push(hidden) 15 | #endif 16 | 17 | int select_open(lua_State *L); 18 | 19 | #ifndef _WIN32 20 | #pragma GCC visibility pop 21 | #endif 22 | 23 | #endif /* SELECT_H */ 24 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef TCP_H 2 | #define TCP_H 3 | /*=========================================================================*\ 4 | * TCP object 5 | * LuaSocket toolkit 6 | * 7 | * The tcp.h module is basicly a glue that puts together modules buffer.h, 8 | * timeout.h socket.h and inet.h to provide the LuaSocket TCP (AF_INET, 9 | * SOCK_STREAM) support. 10 | * 11 | * Three classes are defined: master, client and server. The master class is 12 | * a newly created tcp object, that has not been bound or connected. Server 13 | * objects are tcp objects bound to some local address. Client objects are 14 | * tcp objects either connected to some address or returned by the accept 15 | * method of a server object. 16 | \*=========================================================================*/ 17 | #include "luasocket.h" 18 | 19 | #include "buffer.h" 20 | #include "timeout.h" 21 | #include "socket.h" 22 | 23 | typedef struct t_tcp_ { 24 | t_socket sock; 25 | t_io io; 26 | t_buffer buf; 27 | t_timeout tm; 28 | int family; 29 | } t_tcp; 30 | 31 | typedef t_tcp *p_tcp; 32 | 33 | #ifndef _WIN32 34 | #pragma GCC visibility push(hidden) 35 | #endif 36 | 37 | int tcp_open(lua_State *L); 38 | 39 | #ifndef _WIN32 40 | #pragma GCC visibility pop 41 | #endif 42 | 43 | #endif /* TCP_H */ 44 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMEOUT 2 | #define TIMEOUT 3 | /*=========================================================================*\ 4 | * Timeout management functions 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | #include "luasocket.h" 8 | 9 | /* timeout control structure */ 10 | typedef struct t_timeout_ { 11 | double block; /* maximum time for blocking calls */ 12 | double total; /* total number of miliseconds for operation */ 13 | double start; /* time of start of operation */ 14 | } t_timeout; 15 | typedef t_timeout *p_timeout; 16 | 17 | #ifndef _WIN32 18 | #pragma GCC visibility push(hidden) 19 | #endif 20 | 21 | void timeout_init(p_timeout tm, double block, double total); 22 | double timeout_get(p_timeout tm); 23 | double timeout_getstart(p_timeout tm); 24 | double timeout_getretry(p_timeout tm); 25 | p_timeout timeout_markstart(p_timeout tm); 26 | 27 | double timeout_gettime(void); 28 | 29 | int timeout_open(lua_State *L); 30 | 31 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); 32 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm); 33 | 34 | #ifndef _WIN32 35 | #pragma GCC visibility pop 36 | #endif 37 | 38 | #define timeout_iszero(tm) ((tm)->block == 0.0) 39 | 40 | #endif /* TIMEOUT */ 41 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef UDP_H 2 | #define UDP_H 3 | /*=========================================================================*\ 4 | * UDP object 5 | * LuaSocket toolkit 6 | * 7 | * The udp.h module provides LuaSocket with support for UDP protocol 8 | * (AF_INET, SOCK_DGRAM). 9 | * 10 | * Two classes are defined: connected and unconnected. UDP objects are 11 | * originally unconnected. They can be "connected" to a given address 12 | * with a call to the setpeername function. The same function can be used to 13 | * break the connection. 14 | \*=========================================================================*/ 15 | #include "luasocket.h" 16 | 17 | #include "timeout.h" 18 | #include "socket.h" 19 | 20 | #define UDP_DATAGRAMSIZE 8192 21 | 22 | typedef struct t_udp_ { 23 | t_socket sock; 24 | t_timeout tm; 25 | int family; 26 | } t_udp; 27 | typedef t_udp *p_udp; 28 | 29 | #ifndef _WIN32 30 | #pragma GCC visibility push(hidden) 31 | #endif 32 | 33 | int udp_open(lua_State *L); 34 | 35 | #ifndef _WIN32 36 | #pragma GCC visibility pop 37 | #endif 38 | 39 | #endif /* UDP_H */ 40 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/unix.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIX_H 2 | #define UNIX_H 3 | /*=========================================================================*\ 4 | * Unix domain object 5 | * LuaSocket toolkit 6 | * 7 | * This module is just an example of how to extend LuaSocket with a new 8 | * domain. 9 | \*=========================================================================*/ 10 | #include "luasocket.h" 11 | 12 | #include "buffer.h" 13 | #include "timeout.h" 14 | #include "socket.h" 15 | 16 | typedef struct t_unix_ { 17 | t_socket sock; 18 | t_io io; 19 | t_buffer buf; 20 | t_timeout tm; 21 | } t_unix; 22 | typedef t_unix *p_unix; 23 | 24 | LUASOCKET_API int luaopen_socket_unix(lua_State *L); 25 | 26 | #endif /* UNIX_H */ 27 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/unixdgram.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIXDGRAM_H 2 | #define UNIXDGRAM_H 3 | /*=========================================================================*\ 4 | * DGRAM object 5 | * LuaSocket toolkit 6 | * 7 | * The dgram.h module provides LuaSocket with support for DGRAM protocol 8 | * (AF_INET, SOCK_DGRAM). 9 | * 10 | * Two classes are defined: connected and unconnected. DGRAM objects are 11 | * originally unconnected. They can be "connected" to a given address 12 | * with a call to the setpeername function. The same function can be used to 13 | * break the connection. 14 | \*=========================================================================*/ 15 | 16 | #include "unix.h" 17 | 18 | #ifndef _WIN32 19 | #pragma GCC visibility push(hidden) 20 | #endif 21 | 22 | int unixdgram_open(lua_State *L); 23 | 24 | #ifndef _WIN32 25 | #pragma GCC visibility pop 26 | #endif 27 | 28 | #endif /* UNIXDGRAM_H */ 29 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/unixstream.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIXSTREAM_H 2 | #define UNIXSTREAM_H 3 | /*=========================================================================*\ 4 | * UNIX STREAM object 5 | * LuaSocket toolkit 6 | * 7 | * The unixstream.h module is basicly a glue that puts together modules buffer.h, 8 | * timeout.h socket.h and inet.h to provide the LuaSocket UNIX STREAM (AF_UNIX, 9 | * SOCK_STREAM) support. 10 | * 11 | * Three classes are defined: master, client and server. The master class is 12 | * a newly created unixstream object, that has not been bound or connected. Server 13 | * objects are unixstream objects bound to some local address. Client objects are 14 | * unixstream objects either connected to some address or returned by the accept 15 | * method of a server object. 16 | \*=========================================================================*/ 17 | #include "unix.h" 18 | 19 | #ifndef _WIN32 20 | #pragma GCC visibility push(hidden) 21 | #endif 22 | 23 | int unixstream_open(lua_State *L); 24 | 25 | #ifndef _WIN32 26 | #pragma GCC visibility pop 27 | #endif 28 | 29 | #endif /* UNIXSTREAM_H */ 30 | -------------------------------------------------------------------------------- /components/modules/lua-socket/src/wsocket.h: -------------------------------------------------------------------------------- 1 | #ifndef WSOCKET_H 2 | #define WSOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Win32 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | 8 | /*=========================================================================*\ 9 | * WinSock include files 10 | \*=========================================================================*/ 11 | #include 12 | #include 13 | 14 | typedef int socklen_t; 15 | typedef SOCKADDR_STORAGE t_sockaddr_storage; 16 | typedef SOCKET t_socket; 17 | typedef t_socket *p_socket; 18 | 19 | #ifndef IPV6_V6ONLY 20 | #define IPV6_V6ONLY 27 21 | #endif 22 | 23 | #define SOCKET_INVALID (INVALID_SOCKET) 24 | 25 | #ifndef SO_REUSEPORT 26 | #define SO_REUSEPORT SO_REUSEADDR 27 | #endif 28 | 29 | #ifndef AI_NUMERICSERV 30 | #define AI_NUMERICSERV (0) 31 | #endif 32 | 33 | #endif /* WSOCKET_H */ 34 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/README: -------------------------------------------------------------------------------- 1 | This provides the automated test scripts used to make sure the library 2 | is working properly. 3 | 4 | The files provided are: 5 | 6 | testsrvr.lua -- test server 7 | testclnt.lua -- test client 8 | 9 | To run these tests, just run lua on the server and then on the client. 10 | 11 | hello.lua -- run to verify if installation worked 12 | 13 | Good luck, 14 | Diego. 15 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/auth/.htaccess: -------------------------------------------------------------------------------- 1 | AuthName "test-auth" 2 | AuthType Basic 3 | AuthUserFile /home/diego/impa/luasocket/test/auth/.htpasswd 4 | Require valid-user 5 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/auth/.htpasswd: -------------------------------------------------------------------------------- 1 | luasocket:$apr1$47u2O.Me$.m/5BWAtt7GVoxsouIPBR1 2 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/cgi/cat: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo Content-type: text/plain 3 | echo 4 | 5 | cat > /tmp/luasocket.cat.tmp 6 | cat /tmp/luasocket.cat.tmp 7 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/cgi/cat-index-html: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo Content-type: text/plain 3 | echo 4 | 5 | cat ../index.html 6 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/cgi/env: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo Content-type: text/plain 3 | echo 4 | 5 | env 6 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/cgi/query-string: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo Content-type: text/plain 3 | echo 4 | echo $QUERY_STRING 5 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/cgi/redirect-loop: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo Location: http://$HTTP_HOST$REQUEST_URI 3 | echo 4 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/cgi/request-uri: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo Content-type: text/plain 3 | echo 4 | echo $REQUEST_URI 5 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/dicttest.lua: -------------------------------------------------------------------------------- 1 | local dict = require"socket.dict" 2 | 3 | print(dict.get("dict://localhost/d:teste")) 4 | 5 | for i,v in pairs(dict.get("dict://localhost/d:teste")) do print(v) end 6 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/excepttest.lua: -------------------------------------------------------------------------------- 1 | local socket = require("socket") 2 | 3 | local finalizer_called 4 | 5 | local func = socket.protect(function(err, ...) 6 | local try = socket.newtry(function() 7 | finalizer_called = true 8 | end) 9 | 10 | if err then 11 | return error(err, 0) 12 | else 13 | return try(...) 14 | end 15 | end) 16 | 17 | local ret1, ret2, ret3 = func(false, 1, 2, 3) 18 | assert(not finalizer_called, "unexpected finalizer call") 19 | assert(ret1 == 1 and ret2 == 2 and ret3 == 3, "incorrect return values") 20 | 21 | ret1, ret2, ret3 = func(false, false, "error message") 22 | assert(finalizer_called, "finalizer not called") 23 | assert(ret1 == nil and ret2 == "error message" and ret3 == nil, "incorrect return values") 24 | 25 | local err = {key = "value"} 26 | ret1, ret2 = pcall(func, err) 27 | assert(not ret1, "error not rethrown") 28 | assert(ret2 == err, "incorrect error rethrown") 29 | 30 | print("OK") 31 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/find-connect-limit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | --[[ 3 | Find out how many TCP connections we can make. 4 | 5 | Use ulimit to increase the max number of descriptors: 6 | 7 | ulimit -n 10000 8 | ulimit -n 9 | 10 | You'll probably need to be root to do this. 11 | ]] 12 | 13 | socket = require "socket" 14 | 15 | host = arg[1] or "google.com" 16 | port = arg[2] or 80 17 | 18 | connections = {} 19 | 20 | repeat 21 | c = assert(socket.connect(hostip or host, 80)) 22 | table.insert(connections, c) 23 | 24 | if not hostip then 25 | hostip = c:getpeername() 26 | print("resolved", host, "to", hostip) 27 | end 28 | 29 | print("connection #", #connections, c, "fd", c:getfd()) 30 | 31 | until false 32 | 33 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/hello.lua: -------------------------------------------------------------------------------- 1 | local socket = require"socket" 2 | local mime = require"mime" 3 | print("Hello from " .. socket._VERSION .. " and " .. mime._VERSION .. "!") 4 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/luasocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/components/modules/lua-socket/test/luasocket.png -------------------------------------------------------------------------------- /components/modules/lua-socket/test/stufftest.lua: -------------------------------------------------------------------------------- 1 | local mime = require("mime") 2 | 3 | function test_dot(original, right) 4 | local result, n = mime.dot(2, original) 5 | assert(result == right, "->" .. result .. "<-") 6 | print("ok") 7 | end 8 | 9 | function test_stuff(original, right) 10 | local result, n = mime.dot(2, original) 11 | assert(result == right, "->" .. result .. "<-") 12 | print("ok") 13 | end 14 | 15 | test_dot("abc", "abc") 16 | test_dot("", "") 17 | test_dot("\r\n", "\r\n") 18 | test_dot("\r\n.", "\r\n..") 19 | test_dot(".\r\n.", "..\r\n..") 20 | test_dot(".\r\n.", "..\r\n..") 21 | test_dot("abcd.\r\n.", "abcd.\r\n..") 22 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/tcp-getoptions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | local socket = require"socket" 4 | 5 | port = 8765 6 | 7 | function pcalltest(msg, o, opt) 8 | local a = { pcall(o.getoption, o, opt) } 9 | if a[1] then 10 | print(msg, opt, unpack(a)) 11 | else 12 | print(msg, opt, 'fail: ' .. a[2]) 13 | end 14 | end 15 | 16 | function options(o) 17 | print("options for", o) 18 | 19 | for _, opt in ipairs{ 20 | "keepalive", "reuseaddr", 21 | "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do 22 | pcalltest("getoption", o, opt) 23 | end 24 | 25 | r = o:getoption'linger' 26 | if r then 27 | print("getoption", "linger", 28 | "on", r.on, 29 | "timeout", r.timeout) 30 | else 31 | print("getoption", "linger", "no result") 32 | end 33 | end 34 | 35 | local m = socket.tcp() 36 | 37 | options(m) 38 | 39 | assert(m:bind("*", port)) 40 | assert(m:listen()) 41 | 42 | options(m) 43 | 44 | m:close() 45 | 46 | local m = socket.bind("*", port) 47 | 48 | options(m) 49 | 50 | local c = socket.connect("localhost", port) 51 | 52 | options(c) 53 | 54 | local s = m:accept() 55 | 56 | options(s) 57 | 58 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/test_bind.lua: -------------------------------------------------------------------------------- 1 | local socket = require "socket" 2 | local u = socket.udp() assert(u:setsockname("*", 5088)) u:close() 3 | local u = socket.udp() assert(u:setsockname("*", 0)) u:close() 4 | local t = socket.tcp() assert(t:bind("*", 5088)) t:close() 5 | local t = socket.tcp() assert(t:bind("*", 0)) t:close() 6 | print("done!") -------------------------------------------------------------------------------- /components/modules/lua-socket/test/test_getaddrinfo.lua: -------------------------------------------------------------------------------- 1 | local socket = require "socket" 2 | local addresses = assert(socket.dns.getaddrinfo("localhost")) 3 | assert(type(addresses) == 'table') 4 | 5 | local ipv4mask = "^%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?$" 6 | 7 | for i, alt in ipairs(addresses) do 8 | if alt.family == 'inet' then 9 | assert(type(alt.addr) == 'string') 10 | assert(alt.addr:find(ipv4mask)) 11 | assert(alt.addr == '127.0.0.1') 12 | end 13 | end 14 | 15 | print("done!") 16 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/test_socket_error.lua: -------------------------------------------------------------------------------- 1 | local socket = require "socket" 2 | 3 | local host, port = "127.0.0.1", "5462" 4 | 5 | assert(socket.bind(host, port)):close() 6 | 7 | local sock = socket.tcp() 8 | sock:settimeout(0) 9 | 10 | local ok, err = sock:connect(host, port) 11 | assert(not ok) 12 | assert('timeout' == err) 13 | 14 | for i = 1, 10 do 15 | -- select pass even if socket has error 16 | local _, rec, err = socket.select(nil, {sock}, 1) 17 | local _, ss = next(rec) 18 | if ss then 19 | assert(ss == sock) 20 | else 21 | assert('timeout' == err, 'unexpected error :' .. tostring(err)) 22 | end 23 | err = sock:getoption("error") -- i get 'connection refused' on WinXP 24 | if err then 25 | print("Passed! Error is '" .. err .. "'.") 26 | os.exit(0) 27 | end 28 | end 29 | 30 | print("Fail! No error detected!") 31 | os.exit(1) 32 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/testsrvr.lua: -------------------------------------------------------------------------------- 1 | socket = require("socket"); 2 | host = host or "localhost"; 3 | port = port or "8383"; 4 | server = assert(socket.bind(host, port)); 5 | ack = "\n"; 6 | while 1 do 7 | print("server: waiting for client connection..."); 8 | control = assert(server:accept()); 9 | while 1 do 10 | command, emsg = control:receive(); 11 | if emsg == "closed" then 12 | control:close() 13 | break 14 | end 15 | assert(command, emsg) 16 | assert(control:send(ack)); 17 | print(command); 18 | ((loadstring or load)(command))(); 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/testsupport.lua: -------------------------------------------------------------------------------- 1 | function readfile(name) 2 | local f = io.open(name, "rb") 3 | if not f then return nil end 4 | local s = f:read("*a") 5 | f:close() 6 | return s 7 | end 8 | 9 | function similar(s1, s2) 10 | return string.lower(string.gsub(s1 or "", "%s", "")) == 11 | string.lower(string.gsub(s2 or "", "%s", "")) 12 | end 13 | 14 | function fail(msg) 15 | msg = msg or "failed" 16 | error(msg, 2) 17 | end 18 | 19 | function compare(input, output) 20 | local original = readfile(input) 21 | local recovered = readfile(output) 22 | if original ~= recovered then fail("comparison failed") 23 | else print("ok") end 24 | end 25 | 26 | local G = _G 27 | local set = rawset 28 | local warn = print 29 | 30 | local setglobal = function(table, key, value) 31 | warn("changed " .. key) 32 | set(table, key, value) 33 | end 34 | 35 | setmetatable(G, { 36 | __newindex = setglobal 37 | }) 38 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/tftptest.lua: -------------------------------------------------------------------------------- 1 | -- load tftpclnt.lua 2 | local tftp = require("socket.tftp") 3 | 4 | -- needs tftp server running on localhost, with root pointing to 5 | -- a directory with index.html in it 6 | 7 | function readfile(file) 8 | local f = io.open(file, "r") 9 | if not f then return nil end 10 | local a = f:read("*a") 11 | f:close() 12 | return a 13 | end 14 | 15 | host = host or "diego.student.princeton.edu" 16 | retrieved, err = tftp.get("tftp://" .. host .."/index.html") 17 | assert(not err, err) 18 | original = readfile("test/index.html") 19 | assert(original == retrieved, "files differ!") 20 | print("passed") 21 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/udp-zero-length-send: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | Show that luasocket returns an error message on zero-length UDP sends, 5 | even though the send is valid, and in fact the UDP packet is sent 6 | to the peer: 7 | 8 | % sudo tcpdump -i lo -n 9 | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode 10 | listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes 11 | 13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0 12 | 13 | ]] 14 | 15 | socket = require"socket" 16 | 17 | s = assert(socket.udp()) 18 | r = assert(socket.udp()) 19 | assert(r:setsockname("*", 5432)) 20 | assert(s:setpeername("127.0.0.1", 5432)) 21 | 22 | ssz, emsg = s:send("") 23 | 24 | print(ssz == 0 and "OK" or "FAIL",[[send:("")]], ssz, emsg) 25 | 26 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/udp-zero-length-send-recv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | Show that luasocket returns an error message on zero-length UDP sends, 5 | even though the send is valid, and in fact the UDP packet is sent 6 | to the peer: 7 | 8 | % sudo tcpdump -i lo -n 9 | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode 10 | listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes 11 | 13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0 12 | 13 | ]] 14 | 15 | socket = require"socket" 16 | 17 | s = assert(socket.udp()) 18 | r = assert(socket.udp()) 19 | assert(r:setsockname("*", 5432)) 20 | assert(s:setpeername("127.0.0.1", 5432)) 21 | 22 | ok, emsg = s:send("") 23 | if ok ~= 0 then 24 | print("send of zero failed with:", ok, emsg) 25 | end 26 | 27 | assert(r:settimeout(2)) 28 | 29 | ok, emsg = r:receive() 30 | 31 | if not ok or string.len(ok) ~= 0 then 32 | print("fail - receive of zero failed with:", ok, emsg) 33 | os.exit(1) 34 | end 35 | 36 | print"ok" 37 | 38 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/udpconnectclnt.lua: -------------------------------------------------------------------------------- 1 | local socket = require"socket" 2 | local udp = socket.udp 3 | local localhost = "127.0.0.1" 4 | local port = assert(arg[1], "missing port argument") 5 | 6 | se = udp(); se:setoption("reuseaddr", true) 7 | se:setsockname(localhost, 5062) 8 | print("se", se:getsockname()) 9 | sc = udp(); sc:setoption("reuseaddr", true) 10 | sc:setsockname(localhost, 5061) 11 | print("sc", sc:getsockname()) 12 | 13 | se:sendto("this is a test from se", localhost, port) 14 | socket.sleep(1) 15 | sc:sendto("this is a test from sc", localhost, port) 16 | socket.sleep(1) 17 | se:sendto("this is a test from se", localhost, port) 18 | socket.sleep(1) 19 | sc:sendto("this is a test from sc", localhost, port) 20 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/udpconnectsrvr.lua: -------------------------------------------------------------------------------- 1 | local socket = require"socket" 2 | local udp = socket.udp 3 | local localhost = "127.0.0.1" 4 | local s = assert(udp()) 5 | assert(tostring(s):find("udp{unconnected}")) 6 | print("setpeername", s:setpeername(localhost, 5061)) 7 | print("getsockname", s:getsockname()) 8 | assert(tostring(s):find("udp{connected}")) 9 | print(s:receive()) 10 | print("setpeername", s:setpeername("*")) 11 | print("getsockname", s:getsockname()) 12 | s:sendto("a", localhost, 12345) 13 | print("getsockname", s:getsockname()) 14 | assert(tostring(s):find("udp{unconnected}")) 15 | print(s:receivefrom()) 16 | s:close() 17 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/unixdgramclnt.lua: -------------------------------------------------------------------------------- 1 | socket = require"socket" 2 | socket.unix = require"socket.unix" 3 | c = assert(socket.unix.dgram()) 4 | print(c:bind("/tmp/bar")) 5 | while 1 do 6 | local l = io.read("*l") 7 | assert(c:sendto(l, "/tmp/foo")) 8 | print(assert(c:receivefrom())) 9 | end 10 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/unixdgramsrvr.lua: -------------------------------------------------------------------------------- 1 | socket = require"socket" 2 | socket.unix = require"socket.unix" 3 | u = assert(socket.unix.dgram()) 4 | assert(u:bind("/tmp/foo")) 5 | while 1 do 6 | x, r = assert(u:receivefrom()) 7 | print(x, r) 8 | assert(u:sendto(">" .. x, r)) 9 | end 10 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/unixstreamclnt.lua: -------------------------------------------------------------------------------- 1 | socket = require"socket" 2 | socket.unix = require"socket.unix" 3 | c = assert(socket.unix.stream()) 4 | assert(c:connect("/tmp/foo")) 5 | while 1 do 6 | local l = io.read() 7 | assert(c:send(l .. "\n")) 8 | end 9 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/unixstreamsrvr.lua: -------------------------------------------------------------------------------- 1 | socket = require"socket" 2 | socket.unix = require"socket.unix" 3 | u = assert(socket.unix.stream()) 4 | assert(u:bind("/tmp/foo")) 5 | assert(u:listen()) 6 | c = assert(u:accept()) 7 | while 1 do 8 | print(assert(c:receive())) 9 | end 10 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/upload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | POST test 4 | 5 | 6 | 7 |
8 |
9 | 10 |

11 | 12 |

13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /components/modules/lua-socket/test/utestsrvr.lua: -------------------------------------------------------------------------------- 1 | socket=require("socket"); 2 | os.remove("/tmp/luasocket") 3 | socket.unix = require("socket.unix"); 4 | host = host or "luasocket"; 5 | server = assert(socket.unix()) 6 | assert(server:bind(host)) 7 | assert(server:listen(5)) 8 | ack = "\n"; 9 | while 1 do 10 | print("server: waiting for client connection..."); 11 | control = assert(server:accept()); 12 | while 1 do 13 | command = assert(control:receive()); 14 | assert(control:send(ack)); 15 | ((loadstring or load)(command))(); 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /components/modules/lua-socket/vc32.bat: -------------------------------------------------------------------------------- 1 | call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" 2 | cls 3 | "c:\Program Files\Git\git-bash.exe" --cd-to-home 4 | -------------------------------------------------------------------------------- /components/modules/lua-socket/vc64.bat: -------------------------------------------------------------------------------- 1 | call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" 2 | cls 3 | "c:\Program Files\Git\git-bash.exe" --cd-to-home 4 | -------------------------------------------------------------------------------- /components/modules/lua-socket/win32.cmd: -------------------------------------------------------------------------------- 1 | LUAV=5.3 PLAT=win32 LUAPREFIX_win32=/z/data/build/vc14 make 2 | -------------------------------------------------------------------------------- /components/modules/lua-socket/win64.cmd: -------------------------------------------------------------------------------- 1 | LUAV=5.3 PLAT=win64 LUAPREFIX_win64=/z/data/build/vc14 make 2 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/include/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef BFC4EF52_B7CF_4ACC_8F52_18CDBF1C2DF5 2 | #define BFC4EF52_B7CF_4ACC_8F52_18CDBF1C2DF5 3 | 4 | #ifndef __CRC_H__ 5 | #define __CRC_H__ 6 | 7 | #ifndef uint8_t 8 | #define uint8_t unsigned char 9 | #define uint16_t unsigned short 10 | #define uint32_t unsigned int 11 | #define BOOL unsigned char 12 | #define TRUE 1 13 | #define FALSE 0 14 | #endif 15 | 16 | #include "string.h" 17 | 18 | //uint16_t calcCRC16(const uint8_t *data, uint32_t length); 19 | uint8_t calcCRC8(const uint8_t *buf, uint32_t len); 20 | uint16_t calcCRC16(const uint8_t *data, const char *cmd, int length, uint16_t poly, uint16_t initial, uint16_t finally, BOOL bInReverse, BOOL bOutReverse); 21 | uint16_t calcCRC16_modbus(const uint8_t *data, uint32_t length); 22 | #endif 23 | 24 | 25 | #endif /* BFC4EF52_B7CF_4ACC_8F52_18CDBF1C2DF5 */ 26 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/include/lua_bsp_config.h: -------------------------------------------------------------------------------- 1 | #ifndef A7B8049C_BF61_4C7C_B78E_8BB3D83D6AE2 2 | #define A7B8049C_BF61_4C7C_B78E_8BB3D83D6AE2 3 | 4 | 5 | #define LUA_CONF_LAUX_BUFFSIZE 1024 6 | 7 | #endif /* A7B8049C_BF61_4C7C_B78E_8BB3D83D6AE2 */ 8 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/include/lua_c_api.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_C_API_H 2 | #define LUA_C_API_H 3 | #include 4 | #include "tuya_cloud_types.h" 5 | #include "tuya_list.h" 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | #ifndef RTLD_DEFAULT 10 | #define RTLD_DEFAULT ((void *)0) 11 | #endif 12 | 13 | typedef struct { 14 | LIST_HEAD list; 15 | char name[64]; 16 | void *api_handle; 17 | }CAPI_DECS_T; 18 | 19 | void lua_capi_registor_api_map(const char *name, void *fun); 20 | 21 | void *lua_capi_dlopen(void); 22 | 23 | void *lua_capi_dlsym(void *handle,const char *symbol); 24 | 25 | char* lua_cpai_dlerror(void); 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif /* LUA_C_API */ 30 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/include/lua_main.h: -------------------------------------------------------------------------------- 1 | #ifndef B1196B17_B230_4F14_862F_045F143991BE 2 | #define B1196B17_B230_4F14_862F_045F143991BE 3 | 4 | int lua_task_start(char *luafile,int stack_size); 5 | 6 | int lua_set_script_path(char *path,int index); 7 | 8 | int lua_set_app_info(char *name,char *ver); 9 | 10 | int lua_handle_input(bool force); 11 | 12 | #endif /* B1196B17_B230_4F14_862F_045F143991BE */ 13 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/include/lua_msgbus.h: -------------------------------------------------------------------------------- 1 | #ifndef F9A96612_BB1A_42B1_A48C_2A2F96B40080 2 | #define F9A96612_BB1A_42B1_A48C_2A2F96B40080 3 | 4 | #ifndef LUAT_MSGBUS_H 5 | #define LUAT_MSGBUS_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include "tuya_cloud_types.h" 11 | #include "lua.h" 12 | 13 | #define MSG_TIMER 1 14 | 15 | typedef int (*LUA_MSG_HANDLE) (lua_State *L, void* ptr); 16 | 17 | typedef struct rtos_msg{ 18 | LUA_MSG_HANDLE handler; 19 | void* ptr; 20 | int arg1; 21 | int arg2; 22 | }TUYA_RTOS_MSG_T; 23 | 24 | 25 | // 定义接口方法 26 | void lua_msgbus_init(void); 27 | OPERATE_RET lua_msgbus_put(TUYA_RTOS_MSG_T* msg, size_t timeout); 28 | OPERATE_RET lua_msgbus_get(TUYA_RTOS_MSG_T* msg, size_t timeout); 29 | #define lua_msgbug_put2(ABC1,ABC2,ABC3,ABC4,ABC5) {\ 30 | TUYA_RTOS_MSG_T _msg = {.handler=ABC1,.ptr=ABC2,.arg1=ABC3,.arg2=ABC4};\ 31 | lua_msgbus_put(&_msg, ABC5);\ 32 | } 33 | 34 | #endif 35 | 36 | 37 | #endif /* F9A96612_BB1A_42B1_A48C_2A2F96B40080 */ 38 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/include/lua_timer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef LUAT_TIMER_H 3 | #define LUAT_TIMER_H 4 | 5 | #include "lua.h" 6 | #include "lauxlib.h" 7 | #include "lualib.h" 8 | 9 | #include "lua_msgbus.h" 10 | #include "tal_sw_timer.h" 11 | 12 | typedef struct 13 | { 14 | TIMER_ID os_timer; 15 | size_t timeout; 16 | size_t type; 17 | 18 | lua_State *L; 19 | int func_ref; 20 | int arg_ref; 21 | }LUA_TIMER_T; 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/include/lua_zbuff.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_ZBUFF 2 | #define LUA_ZBUFF 3 | #ifndef LUAT_ZBUFF_H 4 | #define LUAT_ZBUFF_H 5 | 6 | #include "tuya_cloud_types.h" 7 | #include "tal_memory.h" 8 | 9 | #define LUA_ZBUFF_TYPE "ZBUFF*" 10 | #define tozbuff(L) ((LUA_ZBUFF_T *)luaL_checkudata(L, 1, LUA_ZBUFF_TYPE)) 11 | 12 | #define ZBUFF_SEEK_SET 0 13 | #define ZBUFF_SEEK_CUR 1 14 | #define ZBUFF_SEEK_END 2 15 | 16 | #if defined ( __CC_ARM ) 17 | #pragma anon_unions 18 | #endif 19 | 20 | typedef struct luat_zbuff { 21 | uint8_t* addr; //数据存储的地址 22 | size_t len; //实际分配空间的长度 23 | union { 24 | size_t cursor; //目前的指针位置,表明了处理了多少数据 25 | size_t used; //已经保存的数据量,表明了存了多少数据 26 | }; 27 | 28 | uint32_t width; //宽度 29 | uint32_t height;//高度 30 | uint8_t bit; //色深度 31 | } LUA_ZBUFF_T; 32 | 33 | 34 | int __zbuff_resize(LUA_ZBUFF_T *buff, uint32_t new_size); 35 | 36 | #define lua_zbuff_malloc(a) tal_malloc(a) 37 | #define lua_zbuff_free(a) tal_free(a) 38 | 39 | // #define CONFIG_FRAMEBUFFER 1 40 | 41 | 42 | #endif 43 | 44 | 45 | #endif /* LUA_ZBUFF */ 46 | -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/src/lua_base.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | 3 | #include "lauxlib.h" 4 | #include "lualib.h" 5 | #include "rotable2.h" 6 | void luaL_newlib2(lua_State* l, const rotable_Reg_t* reg) { 7 | #ifdef LUAT_CONF_DISABLE_ROTABLE 8 | luaL_newlib(l,reg); 9 | int i; 10 | int nup = 0; 11 | 12 | luaL_checkstack(l, nup, "too many upvalues"); 13 | for (; reg->name != NULL; reg++) { /* fill the table with given functions */ 14 | for (i = 0; i < nup; i++) /* copy upvalues to the top */ 15 | lua_pushvalue(l, -nup); 16 | if (reg->value.value.func) 17 | lua_pushcclosure(l, reg->value.value.func, nup); /* closure with those upvalues */ 18 | else 19 | lua_pushinteger(l, reg->value.value.intvalue); 20 | lua_setfield(l, -(nup + 2), reg->name); 21 | } 22 | lua_pop(l, nup); /* remove upvalues */ 23 | #else 24 | rotable2_newlib(l, reg); 25 | #endif 26 | } -------------------------------------------------------------------------------- /components/modules/lua-tuyaopen/src/lua_msgbus.c: -------------------------------------------------------------------------------- 1 | #include "tal_queue.h" 2 | #include "lua_msgbus.h" 3 | static QUEUE_HANDLE s_queue = NULL; 4 | 5 | 6 | /* 7 | 在 FreeRTOS 中,直接从 Lua 脚本注册中断到驱动可能会带来以下后果: 8 | 9 | 性能影响:Lua 是一种解释型脚本语言,其执行速度通常比编译型语言(如 C/C++)慢。将中断处理程序(ISR)直接注册到 Lua 脚本可能会导致 ISR 的执行速度变慢,从而影响整个系统的性能。 10 | 11 | 实时性影响:在实时操作系统(如 FreeRTOS)中,中断处理程序需要尽快执行并返回,以确保系统的实时性。由于 Lua 脚本的执行速度较慢,直接在 Lua 中处理中断可能会导致实时性降低。 12 | 13 | 内存消耗:Lua 使用垃圾回收机制来管理内存,这可能会导致内存碎片和额外的内存开销。在资源受限的嵌入式系统中,这可能会导致内存不足的问题。 14 | 15 | 中断安全问题:在中断处理程序中,通常需要遵循一些特定的编程规则,以确保中断安全。在 Lua 脚本中处理中断可能会导致意外的行为,例如死锁、数据竞争等。 16 | 17 | 调试困难:在 Lua 脚本中处理中断可能会使得调试变得更加困难,因为你需要同时跟踪 C/C++ 代码和 Lua 脚本的执行。 18 | 19 | 为了避免这些问题,建议在 C/C++ 代码中处理中断,并在需要时通过回调函数或其他机制将事件传递给 Lua 脚本。这样,你可以充分利用 C/C++ 代码的性能优势,同时保持系统的实时性和稳定性。 20 | 21 | 所以我们这里使用发送消息给lua,以便提升性能 22 | */ 23 | 24 | 25 | void lua_msgbus_init(void) { 26 | if (!s_queue) { 27 | tal_queue_create_init(&s_queue,sizeof(TUYA_RTOS_MSG_T),256); 28 | } 29 | } 30 | OPERATE_RET lua_msgbus_put(TUYA_RTOS_MSG_T* msg, size_t timeout) { 31 | if (s_queue == NULL) 32 | return 1; 33 | return tal_queue_post(s_queue,msg,timeout); 34 | } 35 | OPERATE_RET lua_msgbus_get(TUYA_RTOS_MSG_T* msg, size_t timeout) { 36 | if (s_queue == NULL) 37 | return 1; 38 | return tal_queue_fetch(s_queue,msg,timeout); 39 | } 40 | -------------------------------------------------------------------------------- /lua_samples/base/base.lua: -------------------------------------------------------------------------------- 1 | -- test lua base module 2 | -- such as sting, table 3 | 4 | print("Hello world") 5 | 6 | str="test" 7 | print(string.len(str)) -- lua string module 8 | print(string.sub(str, 1, 2)) 9 | 10 | t={11,22,33,44,55} 11 | for k,v in pairs(t) do print(k,v) end 12 | table.remove(t, 3) -- use table module to remove the third element from table t 13 | for k,v in pairs(t) do print(k,v) end 14 | table.insert(t, 2, 99) -- insert 99 to t at index 2 15 | for k,v in pairs(t) do print(k,v) end 16 | 17 | 18 | foo = function() 19 | print("This is a function") 20 | end 21 | foo(); -- function test 22 | -------------------------------------------------------------------------------- /lua_samples/file/file.lua: -------------------------------------------------------------------------------- 1 | -- FS information, format operation 2 | -- List 3 | for k,v in pairs(io.list("/")) do print(k, v) end 4 | 5 | -- exist 6 | print(io.exists("init.lua")) 7 | print(io.exists("test.lua")) 8 | 9 | -- size 10 | print(io.filesize("init.lua")) 11 | -------------------------------------------------------------------------------- /lua_samples/file/file_read.lua: -------------------------------------------------------------------------------- 1 | -- Read an existing file 2 | 3 | -- read all character from the file 4 | fd = io.open("init.lua", "r") 5 | if fd then 6 | content = fd:read('a') 7 | print(content) 8 | 9 | fd:seek("cur", -#content) 10 | content = fd:read(10) 11 | print(content) 12 | 13 | content = fd:read('L') 14 | print(content) 15 | fd:close() 16 | end 17 | -------------------------------------------------------------------------------- /lua_samples/file/file_remove.lua: -------------------------------------------------------------------------------- 1 | -- Remove file 2 | 3 | fd = io.open("test.lua", "w") 4 | if fd then 5 | fd:close() 6 | for k,v in pairs(io.list("/")) do print(k, v) end 7 | io.remove("test.lua") 8 | for k,v in pairs(io.list("/")) do print(k, v) end 9 | end 10 | -------------------------------------------------------------------------------- /lua_samples/file/file_write.lua: -------------------------------------------------------------------------------- 1 | -- file create and write 2 | -- To write a file, you should open it first 3 | 4 | fd = io.open("test.lua","w") 5 | if fd then 6 | fd:write("hello") 7 | fd:write(" ") 8 | fd:write("world") 9 | fd:close() 10 | 11 | fd = io.open("test.lua","r") 12 | content = fd:read('a') 13 | print(content, #content) 14 | fd:close() 15 | io.remove("test.lua") 16 | end 17 | 18 | 19 | -------------------------------------------------------------------------------- /lua_samples/gpio/gpio_in.lua: -------------------------------------------------------------------------------- 1 | -- Read gpio pin 2 | -- gpio.open(pin, mode, value) 3 | -- for INPUT, value can be: PULLUP, PULLDOWN and FLOATING 4 | 5 | gpio.open(3, gpio.INPUT, gpio.FLOATING) -- 6 | ret, level = gpio.read(3) -- read gpio level 7 | print(ret, level) -- ret: 0 is success 8 | -------------------------------------------------------------------------------- /lua_samples/gpio/gpio_intr.lua: -------------------------------------------------------------------------------- 1 | -- connect GPIO5 to GPIO4 2 | -- GPIO4 will be triggered when GPIO5 output different level 3 | 4 | -- pin: pin to set 5 | -- pin_type: the value can be: gpio.INPUT/gpio.OUTPUT/gpio.INT/gpio.INOUT 6 | -- intr_type: how to trigger, the value is string, can be: "up"/"down"/"both"/"low"/"high" 7 | -- callback: callback function 8 | 9 | -- to remove a callback call: gpio.remove(pin) 10 | -- to remove all GPIO ISR call: gpio.uninstall() 11 | 12 | pin_intr = 4; 13 | pin_out = 5; 14 | callback = function() 15 | print("run callback"); 16 | end 17 | 18 | -- gpio.open(pin, mode, value), value is default status 19 | -- for OUTPUT, value can be: LOW, HIGH 20 | -- for INPUT, value can be: PULLUP, PULLDOWN and FLOATING 21 | gpio.open(pin_intr, gpio.INPUT, gpio.FLOATING) 22 | gpio.open(pin_out, gpio.OUTPUT, gpio.LOW) 23 | 24 | -- gpio.set_irq(pin, mode, callback) 25 | -- mode support: IRQ_RISE, IRQ_FALL, IRQ_BOTH, IRQ_LOW, IRQ_HIGH 26 | gpio.set_irq(pin_intr, gpio.IRQ_FALL, callback) 27 | gpio.enable_irq(pin_intr) 28 | 29 | -- delay and trigger the interrupt 30 | sys.delay_ms(2000) 31 | gpio.write(pin_out, gpio.HIGH) 32 | sys.delay_ms(1000) 33 | gpio.write(pin_out, gpio.LOW) 34 | 35 | -- close the pin 36 | gpio.close(pin_intr) 37 | gpio.close(pin_out) -------------------------------------------------------------------------------- /lua_samples/gpio/gpio_out.lua: -------------------------------------------------------------------------------- 1 | -- GPIO sample 2 | -- gpio.open(pin, mode, value) 3 | -- value is default status, for OUTPUT, value can be: LOW, HIGH 4 | 5 | gpio.mode(2, gpio.OUTPUT, gpio.LOW); 6 | gpio.write(2, gpio.HIGH); -- led on 7 | gpio.write(2, gpio.LOW); -- led off 8 | 9 | -------------------------------------------------------------------------------- /lua_samples/gpio/led_blink.lua: -------------------------------------------------------------------------------- 1 | -- LED blink 2 | -- The pin 2 connect to a LED. When the pin output high level, the LED will be light up, 3 | -- otherwise, the LED will be turned off 4 | 5 | isOff = false 6 | 7 | led_blink = function() 8 | if(isOff) then 9 | gpio.write(2, gpio.HIGH); -- turn on 10 | isOff = false 11 | else 12 | gpio.write(2, gpio.LOW); -- turn off 13 | isOff = true 14 | end 15 | end 16 | 17 | gpio.open(2, gpio.OUTPUT, gpio.LOW); 18 | tmr = timer.start(1000, timer.CYCLE, led_blink) 19 | 20 | -- timer.stop(tmr) 21 | -- timer.delete(tmr) 22 | -------------------------------------------------------------------------------- /lua_samples/http/file_download.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/lua_samples/http/file_download.lua -------------------------------------------------------------------------------- /lua_samples/http/file_upload.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/lua_samples/http/file_upload.lua -------------------------------------------------------------------------------- /lua_samples/http/http.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/lua_samples/http/http.lua -------------------------------------------------------------------------------- /lua_samples/http/https.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/lua_samples/http/https.lua -------------------------------------------------------------------------------- /lua_samples/net/net_connection.lua: -------------------------------------------------------------------------------- 1 | -- test luanode-tuyaopen network connections module 2 | -- note: 3 | -- the network connection module was default starup in tuyaos demo 4 | -- so you don't need to call the conn.init() if you already call tuyaos.start_device() 5 | 6 | -- init the network connection module 7 | -- it will manage the network connections of the board, Wi-Fi or wired. 8 | conn.init() 9 | 10 | -- get the network connection type 11 | conn.supported() 12 | 13 | -- check the network status 14 | conn.isup() -- the connection status 15 | -- conn.isup("wifi") -- the connection status of Wi-Fi link (if have Wi-Fi link) 16 | -- conn.isup("wired") -- the connection status of wired link (if have wired link) 17 | 18 | -- get the network info 19 | conn.ip() 20 | conn.mac() 21 | 22 | 23 | -- change the default network connction 24 | -- this command works only when more than 1 connections up 25 | -- conn.switch("wired") 26 | -- conn.switch("wifi") -------------------------------------------------------------------------------- /lua_samples/net/net_tcp_server.lua: -------------------------------------------------------------------------------- 1 | -- test luanode-tuyaopen network module 2 | -- test lua-socket udp server 3 | -- note: 4 | -- the network connection module was default starup in tuyaos demo 5 | -- so you don't need to call the conn.init() if you already call tuyaos.start_device() 6 | 7 | -- init the network connection module 8 | -- it will manage the network connections of the board, Wi-Fi or wired. 9 | conn.init() 10 | 11 | -- if the board connect to network use Wi-Fi, we should connect to router first 12 | -- conn.connect("test-wifi-ssid", "test-wifi-passwd") 13 | 14 | -- wait until the Wi-Fi link is up 15 | while true do 16 | -- get the linkstatus 17 | isup = conn.isup() 18 | if isup then 19 | s = socket.tcp() 20 | s:settimeout(0) 21 | s:bind("*", 6666) 22 | s:listen(2) 23 | while true do 24 | -- accept a cleint 25 | c = s:accept() 26 | c:settimeout(10) 27 | line, err = c:receive() 28 | if not err then 29 | print("Receive from client "..line) 30 | c:send("hello, this is tcp server!") 31 | end 32 | 33 | -- close client 34 | c:close() 35 | end 36 | end 37 | 38 | -- delay 1000ms waiting for connecting 39 | sys.delay_ms(1000) 40 | end -------------------------------------------------------------------------------- /lua_samples/net/wifi_ap.lua: -------------------------------------------------------------------------------- 1 | -- test luanode-tuyaopen network module 2 | -- test Wi-Fi ap functions if the network connction type is Wi-Fi, 3 | -- note: 4 | -- the network connection module was default starup in tuyaos demo 5 | -- so you don't need to call the conn.init() if you already call tuyaos.start_device() 6 | 7 | -- init the network connection module 8 | conn.init() 9 | 10 | -- check if the network have Wi-Fi connection 11 | conn.current() 12 | 13 | -- start a open ap 14 | -- for a WPA/WPA2 ap: ap_info = {ssid="test-ssid", passwd="1Q@w3e$R", ip="192.168.176.1"} 15 | ap_info = {ssid="test-ssid", ip="192.168.176.1"} 16 | conn.start_ap(ap_info) 17 | 18 | -- stop the ap 19 | conn.stop_ap() 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /lua_samples/net/wifi_sta.lua: -------------------------------------------------------------------------------- 1 | -- test luanode-tuyaopen network module 2 | -- test Wi-Fi ap functions if the network connction type is Wi-Fi, 3 | -- note: 4 | -- the network connection module was default starup in tuyaos demo 5 | -- so you don't need to call the conn.init() if you already call tuyaos.start_device() 6 | 7 | -- init the network connection module 8 | conn.init() 9 | 10 | -- check if the network have Wi-Fi connection 11 | conn.current() 12 | 13 | -- start a open ap 14 | ssid = "test-wifi-ssid" 15 | passwd = "test-wifi-passwd" 16 | conn.connect(ssid, passwd) 17 | 18 | -- stop the ap 19 | while true do 20 | isup = conn.isup() 21 | if isup then 22 | print("connect to "..ssid.." passwd "..passwd.." success!") 23 | break 24 | end 25 | 26 | -- delay 1000ms waiting for connecting 27 | sys.delay_ms(1000) 28 | end 29 | 30 | conn.disconnect() 31 | 32 | -------------------------------------------------------------------------------- /lua_samples/system/system.lua: -------------------------------------------------------------------------------- 1 | -- test system module 2 | -- get firmware info 3 | sys.info() 4 | 5 | -- get firmware free heap 6 | sys.heap() 7 | 8 | -- get a random integer 9 | sys.reandom(255) 10 | 11 | -- reset chip 12 | sys.reset() 13 | 14 | -- after reset, check the reason 15 | sys.reset_reason() 16 | -------------------------------------------------------------------------------- /lua_samples/system/timer.lua: -------------------------------------------------------------------------------- 1 | -- current local time 2 | -- note: 3 | -- this function only valid when tuyaos activated!!! 4 | sys.now() 5 | 6 | -- sleep 5000ms 7 | sys.sleep_ms(5000) 8 | print("hello tuyaopen") 9 | 10 | -- delay 5000ms 11 | sys.delay_ms(5000) 12 | print("hello tuyaopen") -------------------------------------------------------------------------------- /lua_samples/thread/thread_file.lua: -------------------------------------------------------------------------------- 1 | -- luaproc: https://github.com/askyrme/luaproc/blob/master/README.md 2 | -- Thread run only once 3 | -- The thread will run a string 4 | fd = io.open("test.lua", "w") 5 | fd:write("print('hello, world!')") 6 | fd:close() 7 | 8 | luaproc.newproc("dofile('test.lua')") 9 | -------------------------------------------------------------------------------- /lua_samples/thread/thread_function.lua: -------------------------------------------------------------------------------- 1 | -- luaproc: https://github.com/askyrme/luaproc/blob/master/README.md 2 | -- Start a thread for LED blinking 3 | -- Print status of the thread 4 | 5 | f1=function() 6 | while true do 7 | gpio.write(2,0) 8 | sys.delay_ms(1000) 9 | gpio.write(2,1) 10 | sys.delay_ms(1000) 11 | end 12 | end 13 | 14 | -- add new workers for this function 15 | cnt = luaproc.getnumworkers() 16 | luaproc.setnumworkers(cnt + 1) 17 | luaproc.newproc(f1); -------------------------------------------------------------------------------- /lua_samples/thread/thread_function_once.lua: -------------------------------------------------------------------------------- 1 | -- luaproc: https://github.com/askyrme/luaproc/blob/master/README.md 2 | -- Thread run only once 3 | -- The thread will exit when it run once 4 | 5 | f1 = function() 6 | print("thread start") 7 | sys.delay_ms(5000) -- do somthing 8 | print("thread end") 9 | end 10 | 11 | luaproc.newproc(f1) 12 | -------------------------------------------------------------------------------- /lua_samples/thread/thread_string.lua: -------------------------------------------------------------------------------- 1 | -- luaproc: https://github.com/askyrme/luaproc/blob/master/README.md 2 | -- The thread will run a string 3 | -- check how many package was loaded in package.preload 4 | luaproc.newproc("for k,v in pairs(package.loaded) do print(k,v) end") 5 | -------------------------------------------------------------------------------- /lua_samples/timer/timer_callback.lua: -------------------------------------------------------------------------------- 1 | -- Register call back for a timer 2 | -- Timer trigger each period, change parameter to tmr.ALARM_SINGLE to trigger once 3 | a={v=0} 4 | callback = function(a) print("times up ".. a.v) a.v= a.v+1 end 5 | 6 | -- start a timer, callback once after 5000ms 7 | -- timer.start(timerout_in_ms, timer.ONCE or timer.CYCLE, callback, parameter for callback) 8 | tmr = timer.start(5000, 1, callback, a) 9 | 10 | -- trigger timer immideately 11 | timer.trigger(tmr) 12 | 13 | -- stop timer 14 | timer.stop(tmr) 15 | 16 | -- delete timer 17 | timer.delete(tmr) 18 | 19 | -------------------------------------------------------------------------------- /lua_samples/uart/uart.lua: -------------------------------------------------------------------------------- 1 | -- The uart module provide the following method 2 | -- 3 | -- 1. uart.open(id, baud, [databits], [parity], [stopbits], [flow_ctrl], [txd], [rxd], [rts], [cts]) 4 | -- id: the uart number 5 | -- baud: the uart baud rate 6 | -- databits: can be the following constants: uart.DATA_8_BITS/uart.DATA_7_BITS/uart.DATA_6_BITS/uart.DATA_5_BITS 7 | -- parity: can be uart.PARITY_NONE/uart.PARITY_ODD/uart.PARITY_EVEN 8 | -- stopbits: can be uart.STOPBITS_1/uart.STOPBITS_1_5/uart.STOPBITS_2 9 | -- flow_ctrl: flow control enable. normally set to uart.FLOWCTRL_NONE 10 | -- txd: pin of txd, optional, default pin is GPIO4 11 | -- rxd: pin of rxd, optional, default pin is GPIO5 12 | -- rts: pin of rts, optional, default pin is GPIO18 13 | -- cts: pin of cts, optional, default is GPIO19 14 | -- 2. uart.write(id, string1, [string2], ..., [stringn]) 15 | -- 3. uart.read(id) 16 | -- 3. uart.close(id) 17 | 18 | uart.open(uart.UART_0, 115200, uart.DATA_8_BITS, uart.PARITY_NONE, uart.STOPBITS_1, uart.FLOWCTRL_NONE) 19 | while true do 20 | sys.delay(2); 21 | uart.write(uart.UART_0, "hello"); 22 | end 23 | 24 | uart.close(uart.UART_0) -------------------------------------------------------------------------------- /lua_samples/utils/utils.lua: -------------------------------------------------------------------------------- 1 | -- utils module 2 | 3 | str = "hello, this is tuyaopen" 4 | 5 | -- base64 6 | encodeStr = utils.base64_encode(str) 7 | decodeStr = utils.base64_decode(encodeStr) 8 | 9 | -- md5 10 | utils.md5(str) 11 | 12 | -- crc8,16,32 13 | utils.crc8(str) 14 | utils.crc16(str) 15 | utils.crc32(str) 16 | 17 | -- sha1,sha256 18 | utils.sha1(str) 19 | utils.sha256(str) 20 | 21 | -- hmac 22 | key = "1qaz3edc" 23 | utils.hmac_md5(str, key) 24 | utils.hmac_sha1(str, key) 25 | utils.hmac_sha256(str, key) 26 | 27 | -------------------------------------------------------------------------------- /main/project_build.ini: -------------------------------------------------------------------------------- 1 | [project:main] 2 | platform = ubuntu 3 | 4 | -------------------------------------------------------------------------------- /main/src/uart_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef _UART_HANDLER_H_ 2 | #define _UART_HANDLER_H_ 3 | 4 | 5 | void uart_init(void); 6 | int uart_getc(char *c); 7 | int uart_getline(const char *prompt, char *c, int len); 8 | int uart_tx_one_char(char c); 9 | #endif 10 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | 7 | [*.py] 8 | indent_style = space 9 | indent_size = 4 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/.gitignore: -------------------------------------------------------------------------------- 1 | # python-stuff 2 | *.egg-info/ 3 | .eggs 4 | dist/ 5 | build/ 6 | *.pyc 7 | __pycache__/ 8 | 9 | # testing 10 | .coverage 11 | env/ 12 | env3/ 13 | *.log 14 | tmp/ 15 | venv/ 16 | 17 | # editors 18 | .vscode/ 19 | .tox 20 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - 3.6 4 | - 3.7 5 | 6 | # command to install dependencies 7 | install: "pip install -r test_requirements.txt" 8 | 9 | # command to run tests 10 | script: 11 | - coverage run setup.py test 12 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (C) 2015-2020 Peter Magnusson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/doc/DEVELOP.md: -------------------------------------------------------------------------------- 1 | Develop and Test nodemcu-uploader 2 | ================================= 3 | 4 | Configure development environment 5 | ------- 6 | ```shell 7 | git clone https://github.com/kmpm/nodemcu-uploader 8 | cd nodemcu-uploader 9 | python3 -m venv 10 | . venv/bin/activate 11 | pip install -r test_requirements.txt 12 | pip install -e . 13 | ``` 14 | 15 | 16 | 17 | Testing 18 | ------- 19 | ```shell 20 | pip install -r test_requirements.txt 21 | coverage run setup.py test 22 | # or even better testing with tox 23 | tox 24 | ``` 25 | 26 | To run tests that actually communicate with a device you 27 | will need to set the __SERIALPORT__ environment variable 28 | to the port where you have an device connected. 29 | 30 | Linux 31 | ``` 32 | export SERIALPORT=/dev/ttyUSB0 33 | ``` 34 | 35 | 36 | Publishing 37 | ---------- 38 | * https://packaging.python.org/tutorials/packaging-projects/ 39 | 40 | Please make sure to bump the version number in 41 | nodemcu_uploader/version.py as well as the testing of that 42 | number in tests/misc.py 43 | 44 | ```bash 45 | # 46 | python -m pip install --upgrade setuptools wheel twine 47 | python setup.py sdist bdist_wheel 48 | 49 | #test upload 50 | python -m twine upload -u __token__ --repository testpypi dist/* 51 | 52 | #real upload 53 | python -m twine upload -u __token__ dist/* 54 | ``` 55 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu-uploader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # Copyright (C) 2015-2019 Peter Magnusson 4 | # pylint: disable=C0103 5 | """makes it easier to run nodemcu-uploader from command line""" 6 | 7 | from nodemcu_uploader import main 8 | 9 | 10 | if __name__ == '__main__': 11 | main.main_func() 12 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright (C) 2015-2019 Peter Magnusson 4 | 5 | """Library and util for uploading files to NodeMCU version 0.9.4 and later""" 6 | 7 | from .version import __version__ # noqa: F401 8 | from .uploader import Uploader # noqa: F401 9 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/__main__.py: -------------------------------------------------------------------------------- 1 | from .main import main_func 2 | 3 | if __name__ == '__main__': 4 | main_func() 5 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (C) 2015-2019 Peter Magnusson 3 | # pylint: disable=C0111 4 | 5 | """Various custom exceptions""" 6 | 7 | 8 | class CommunicationTimeout(Exception): 9 | def __init__(self, message, buf): 10 | super(CommunicationTimeout, self).__init__(message) 11 | self.buf = buf 12 | 13 | 14 | class BadResponseException(Exception): 15 | def __init__(self, message, expected, actual): 16 | message = message + ' expected:`%s` != actual: `%s`' % (expected, actual) 17 | super(BadResponseException, self).__init__(message) 18 | 19 | self.expected = expected 20 | self.actual = actual 21 | 22 | 23 | class NoAckException(Exception): 24 | pass 25 | 26 | 27 | class DeviceNotFoundException(Exception): 28 | pass 29 | 30 | 31 | class VerificationError(Exception): 32 | pass 33 | 34 | 35 | class PathLengthException(Exception): 36 | pass 37 | 38 | 39 | class ValidationException(Exception): 40 | def __init__(self, message, key, value): 41 | message = "Validation Exception. {key} was {message}. '{value}'".format(message=message, key=key, value=value) 42 | super(ValidationException, self).__init__(message) 43 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/serialutils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (C) 2015-2019 Peter Magnusson 3 | 4 | from platform import system 5 | from os import environ 6 | from serial.tools import list_ports 7 | 8 | 9 | def default_port(sysname=system(), detect=True): 10 | """This returns the default port used for different systems if SERIALPORT env variable is not set""" 11 | system_default = { 12 | 'Windows': 'COM1', 13 | 'Darwin': '/dev/tty.SLAB_USBtoUART' 14 | }.get(sysname, '/dev/ttyUSB0') 15 | # if SERIALPORT is set then don't even waste time detecting ports 16 | if 'SERIALPORT' not in environ and detect: 17 | try: 18 | ports = list_ports.comports(include_links=False) 19 | if len(ports) == 1: 20 | return ports[0].device 21 | else: 22 | # clever guessing, sort of 23 | # vid/pid 24 | # 4292/60000 adafruit huzzah 25 | for p in ports: 26 | if p.vid == 4292 and p.pid == 60000: 27 | return p.device 28 | # use last port as fallback 29 | return ports[-1].device 30 | except Exception: 31 | pass 32 | 33 | return environ.get('SERIALPORT', system_default) 34 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/term.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """Piggyback on pyserial terminal""" 3 | 4 | from serial.tools import miniterm 5 | import sys 6 | 7 | from .serialutils import default_port 8 | 9 | 10 | def terminal(port=default_port(), baud='9600'): 11 | """Launch minterm from pyserial""" 12 | testargs = ['nodemcu-uploader', port, baud] 13 | # TODO: modifying argv is no good 14 | sys.argv = testargs 15 | # resuse miniterm on main function 16 | miniterm.main() 17 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (C) 2015-2019 Peter Magnusson 3 | """Various utility functions""" 4 | 5 | from platform import system 6 | 7 | # from wrapt import ObjectProxy 8 | from sys import version_info 9 | 10 | __all__ = ['system', 'hexify', 'from_file', 'PY2', 'ENCODING'] 11 | 12 | PY2 = version_info.major == 2 13 | 14 | if PY2: 15 | raise Exception("Python 2 is no longer supported") 16 | 17 | ENCODING = 'latin1' 18 | 19 | 20 | def to_hex(x): 21 | if isinstance(x, int): 22 | return hex(x) 23 | return hex(ord(x)) 24 | 25 | 26 | def hexify(byte_arr): 27 | if isinstance(byte_arr, int): 28 | return to_hex(byte_arr)[2:] 29 | else: 30 | return ':'.join((to_hex(x)[2:] for x in byte_arr)) 31 | 32 | 33 | def from_file(path): 34 | """Returns content of file as 'bytes'. 35 | """ 36 | with open(path, 'r') as f: 37 | content = f.read() 38 | return content 39 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/validate.py: -------------------------------------------------------------------------------- 1 | from .exceptions import ValidationException 2 | 3 | MAX_FS_NAME_LEN = 31 4 | 5 | 6 | def remotePath(path): 7 | """Do various checks on the remote file name like max length. 8 | Raises exception if not valid 9 | """ 10 | if len(path) > MAX_FS_NAME_LEN: 11 | raise ValidationException('To long. >{0}'.format(MAX_FS_NAME_LEN), 'path', path) 12 | if len(path) < 1: 13 | raise ValidationException('To short', 'path', path) 14 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/nodemcu_uploader/version.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (C) 2015-2019 Peter Magnusson 3 | """just keeper of current version""" 4 | 5 | # TODO: remember to update tests when version changes 6 | __version__ = '1.0.0' 7 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | persistent=yes 3 | 4 | [FORMAT] 5 | # Maximum number of characters on a single line. 6 | max-line-length=120 7 | 8 | [DESIGN] 9 | max-args=6 10 | max-statements=70 11 | 12 | [MESSAGES CONTROL] 13 | disable=I0011 14 | 15 | [REPORTS] 16 | msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} 17 | include-ids=yes -------------------------------------------------------------------------------- /tools/nodemcu-uploader/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description_file=README.md 3 | licence=LICENSE 4 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/test_requirements.txt: -------------------------------------------------------------------------------- 1 | pyserial==3.4 2 | coverage==4.0.3 3 | flake8==3.7.9 4 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (C) 2015-2019 Peter Magnusson 3 | """Add tests to include here""" 4 | 5 | import unittest 6 | import logging 7 | 8 | def get_tests(): 9 | """returns the tests to run""" 10 | return full_suite() 11 | 12 | def full_suite(): 13 | """creates a full suite of tests""" 14 | logging.basicConfig(filename='test.log', level=logging.INFO, 15 | format='%(asctime)s %(levelname)s %(module)s.%(funcName)s %(message)s') 16 | 17 | from .misc import MiscTestCase 18 | from . import uploader 19 | # from .serializer import ResourceTestCase as SerializerTestCase 20 | # from .utils import UtilsTestCase 21 | 22 | miscsuite = unittest.TestLoader().loadTestsFromTestCase(MiscTestCase) 23 | uploadersuite = unittest.TestLoader().loadTestsFromModule(uploader) 24 | return unittest.TestSuite([miscsuite, uploadersuite]) 25 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tests/fixtures/led_blink.lua: -------------------------------------------------------------------------------- 1 | lighton=0 2 | tmr.alarm(0,1000,1,function() 3 | if lighton==0 then 4 | lighton=1 5 | led(512,512,512) 6 | -- 512/1024, 50% duty cycle 7 | else 8 | lighton=0 9 | led(0,0,0) 10 | end 11 | end) 12 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tests/fixtures/medium_file.txt: -------------------------------------------------------------------------------- 1 | xyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2 | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 3 | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 4 | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 5 | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 6 | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyz 7 | 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tests/fixtures/riazzerawifi.lua: -------------------------------------------------------------------------------- 1 | --riazzerawifi.lua 2 | -- Starts the portal to choose the wi-fi router to which we have 3 | -- to associate 4 | wifi.sta.disconnect() 5 | wifi.setmode(wifi.STATIONAP) 6 | --ESP SSID generated wiht its chipid 7 | wifi.ap.config({ssid="Mynode-"..node.chipid() 8 | , auth=wifi.OPEN}) 9 | enduser_setup.manual(true) 10 | enduser_setup.start( 11 | function() 12 | print("Connected to wifi as:" .. wifi.sta.getip()) 13 | end, 14 | function(err, str) 15 | print("enduser_setup: Err #" .. err .. ": " .. str) 16 | end 17 | ); 18 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tests/fixtures/signatur.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuya/luanode-TuyaOpen/46fe449e94be4e969b7a034ee4b1148eca5b2644/tools/nodemcu-uploader/tests/fixtures/signatur.tif -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tests/fixtures/small_file.txt: -------------------------------------------------------------------------------- 1 | xyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2 | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyz -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tests/fixtures/testuploadfail.txt: -------------------------------------------------------------------------------- 1 | if (anything == false and test > 10) then print ("This line should be fine") end 2 | 3 | -- Doesn't matter what is here, just needs to be enough for another block after the > sign 4 | -- Lorem Ipsum dolor sit amet consecutor adlipsing. Lorem Ipsum dolor sit amet consecutor adlipsing. 5 | -- Lorem Ipsum dolor sit amet consecutor adlipsing.Lorem Ipsum dolor sit amet consecutor adlipsing. 6 | -- Lorem Ipsum dolor sit amet consecutor adlipsing.Lorem Ipsum dolor sit amet consecutor adlipsing. 7 | -------------------------------------------------------------------------------- /tools/nodemcu-uploader/tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py36, py37, py38 3 | 4 | [testenv] 5 | deps = -rtest_requirements.txt 6 | commands = python -m unittest -v tests.get_tests 7 | setenv = 8 | SERIALPORT= 9 | 10 | [flake8] 11 | include = 12 | nodemcu_uploader, 13 | tests 14 | # ignore = E501 15 | max-line-length = 120 16 | --------------------------------------------------------------------------------