├── .github └── workflows │ └── build.yml ├── .gitignore ├── Makefile ├── README.md ├── project ├── modules.mk ├── rules.mk ├── settings.mk └── test.mk ├── src ├── include │ └── aerospike │ │ ├── mod_lua.h │ │ ├── mod_lua_aerospike.h │ │ ├── mod_lua_bytes.h │ │ ├── mod_lua_config.h │ │ ├── mod_lua_geojson.h │ │ ├── mod_lua_iterator.h │ │ ├── mod_lua_list.h │ │ ├── mod_lua_map.h │ │ ├── mod_lua_record.h │ │ ├── mod_lua_reg.h │ │ ├── mod_lua_stream.h │ │ └── mod_lua_val.h ├── main │ ├── internal.c │ ├── internal.h │ ├── mod_lua.c │ ├── mod_lua_aerospike.c │ ├── mod_lua_bytes.c │ ├── mod_lua_geojson.c │ ├── mod_lua_iterator.c │ ├── mod_lua_list.c │ ├── mod_lua_map.c │ ├── mod_lua_record.c │ ├── mod_lua_reg.c │ ├── mod_lua_stream.c │ ├── mod_lua_system.c │ └── mod_lua_val.c └── test │ ├── hash │ └── hash_udf.c │ ├── list │ └── list_udf.c │ ├── lua │ ├── aggr.lua │ ├── basics.lua │ ├── bytes.lua │ ├── errors.lua │ ├── integers.lua │ ├── lists.lua │ ├── logs.lua │ ├── maps.lua │ ├── raj.lua │ ├── records.lua │ ├── strings.lua │ ├── test.lua │ ├── test_bytes.lua │ ├── test_math.lua │ ├── test_unit.lua │ ├── validate_1.lua │ ├── validate_2.lua │ ├── validate_3.lua │ ├── validate_4.lua │ ├── validate_5.lua │ └── validate_6.lua │ ├── mod_lua_test.c │ ├── record │ └── record_udf.c │ ├── stream │ └── stream_udf.c │ ├── test.c │ ├── test.h │ ├── util │ ├── consumer_stream.c │ ├── consumer_stream.h │ ├── map_rec.c │ ├── map_rec.h │ ├── producer_stream.c │ ├── producer_stream.h │ ├── test_aerospike.c │ ├── test_aerospike.h │ ├── test_logger.c │ └── test_logger.h │ └── validation │ └── validation_basics.c ├── vs ├── aerospike-mod-lua-test │ ├── aerospike-mod-lua-test.vcxproj │ ├── aerospike-mod-lua-test.vcxproj.filters │ └── packages.config ├── aerospike-mod-lua.sln ├── aerospike-mod-lua │ ├── aerospike-mod-lua.vcxproj │ ├── aerospike-mod-lua.vcxproj.filters │ └── packages.config └── props │ ├── base.props │ └── test.props └── xcode ├── aerospike-mod-lua-test.xcodeproj └── project.pbxproj ├── aerospike-mod-lua.xcodeproj └── project.pbxproj └── aerospike-mod-lua.xcworkspace ├── contents.xcworkspacedata └── xcshareddata ├── IDEWorkspaceChecks.plist ├── aerospike-mod-lua.xcscmblueprint └── mod-lua.xcscmblueprint /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | 5 | env: 6 | COMMON_REF: master 7 | LUAMOD_REF: v5.4.6 8 | 9 | jobs: 10 | build-n-test: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-latest, macos-latest] 14 | runs-on: ${{ matrix.os }} 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 19 | - uses: actions/checkout@v4 20 | with: 21 | repository: ${{ github.repository_owner }}/aerospike-common 22 | ref: ${{ env.COMMON_REF }} 23 | fetch-depth: 0 24 | token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }} 25 | path: common 26 | - uses: actions/checkout@v4 27 | with: 28 | repository: aerospike/lua 29 | ref: ${{ env.LUAMOD_REF }} 30 | fetch-depth: 0 31 | path: lua 32 | - name: Build 33 | run: "make COMMON=common LUAMOD=lua" 34 | - name: Test 35 | run: "make COMMON=common LUAMOD=lua test" 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | target 3 | /mod_lua_test-valgrind 4 | xcuserdata 5 | *.xccheckout 6 | *.swp 7 | *~.nib 8 | *.suo 9 | *.user 10 | *.VC.db 11 | *.VC.VC.opendb 12 | .vs 13 | Debug 14 | x64 15 | ipch 16 | packages 17 | packages/repositories.config 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | ## SETTINGS ## 3 | ############################################################################### 4 | include project/settings.mk 5 | 6 | # Modules 7 | COMMON := $(COMMON) 8 | LUAMOD := $(LUAMOD) 9 | MODULES := COMMON 10 | MODULES += LUAMOD 11 | 12 | # Override optimizations via: make O=n 13 | O = 3 14 | 15 | # Make-local Compiler Flags 16 | EXT_CFLAGS = 17 | CC_FLAGS = -std=gnu99 -g -fPIC -O$(O) 18 | CC_FLAGS += -fno-common -fno-strict-aliasing 19 | CC_FLAGS += -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_GNU_SOURCE $(EXT_CFLAGS) 20 | 21 | ifeq ($(ARCH),x86_64) 22 | REAL_ARCH = -march=nocona 23 | endif 24 | 25 | ifeq ($(ARCH),aarch64) 26 | REAL_ARCH = -mcpu=neoverse-n1 27 | endif 28 | 29 | CC_CFLAGS += $(REAL_ARCH) 30 | 31 | ifeq ($(TARGET_SERVER), ) 32 | CC_FLAGS += -DAS_MOD_LUA_CLIENT 33 | endif 34 | 35 | # Linker flags 36 | LD_FLAGS = $(LDFLAGS) 37 | 38 | ifeq ($(OS),Darwin) 39 | CC_FLAGS += -D_DARWIN_UNLIMITED_SELECT 40 | LD_FLAGS += -undefined dynamic_lookup 41 | LUA_PLATFORM = LUA_USE_MACOSX 42 | 43 | ifneq ($(wildcard /opt/homebrew/opt/openssl/include),) 44 | # Mac new homebrew openssl include path 45 | CC_FLAGS += -I/opt/homebrew/opt/openssl/include 46 | else ifneq ($(wildcard /usr/local/opt/openssl/include),) 47 | # Mac old homebrew openssl include path 48 | CC_FLAGS += -I/usr/local/opt/openssl/include 49 | else ifneq ($(wildcard /opt/local/include/openssl),) 50 | # macports openssl include path 51 | CC_FLAGS += -I/opt/local/include 52 | endif 53 | else ifeq ($(OS),FreeBSD) 54 | CC_FLAGS += -finline-functions 55 | LUA_PLATFORM = LUA_USE_LINUX # nothing BSD specific in luaconf.h 56 | else 57 | CC_FLAGS += -finline-functions -rdynamic 58 | LUA_PLATFORM = LUA_USE_LINUX 59 | 60 | ifneq ($(wildcard /etc/alpine-release),) 61 | CC_FLAGS += -DAS_ALPINE 62 | endif 63 | endif 64 | 65 | ifneq ($(CF), ) 66 | CC_FLAGS += -I$(CF)/include 67 | endif 68 | 69 | # DEBUG Settings 70 | ifdef DEBUG 71 | O = 0 72 | CC_FLAGS += -pg -fprofile-arcs -ftest-coverage -g2 73 | LD_FLAGS += -pg -fprofile-arcs -lgcov 74 | endif 75 | 76 | # Make-tree Compiler Flags 77 | CFLAGS = -O$(O) 78 | 79 | # Include Paths 80 | INC_PATH += $(COMMON)/$(SOURCE_INCL) 81 | INC_PATH += $(LUAMOD) 82 | 83 | ############################################################################### 84 | ## OBJECTS ## 85 | ############################################################################### 86 | 87 | MOD_LUA = 88 | MOD_LUA += mod_lua.o 89 | MOD_LUA += mod_lua_aerospike.o 90 | MOD_LUA += mod_lua_bytes.o 91 | MOD_LUA += mod_lua_geojson.o 92 | MOD_LUA += mod_lua_iterator.o 93 | MOD_LUA += mod_lua_list.o 94 | MOD_LUA += mod_lua_map.o 95 | MOD_LUA += mod_lua_record.o 96 | MOD_LUA += mod_lua_reg.o 97 | MOD_LUA += mod_lua_stream.o 98 | MOD_LUA += mod_lua_system.o 99 | MOD_LUA += mod_lua_val.o 100 | 101 | ############################################################################### 102 | ## HEADERS ## 103 | ############################################################################### 104 | 105 | MOD_LUA_HS = $(wildcard $(SOURCE_INCL)/aerospike/*.h) 106 | 107 | ############################################################################### 108 | ## MAIN TARGETS ## 109 | ############################################################################### 110 | 111 | all: build prepare 112 | 113 | .PHONY: build 114 | build: modules-build libmod_lua 115 | 116 | .PHONY: prepare 117 | prepare: modules-prepare $(subst $(SOURCE_INCL),$(TARGET_INCL),$(MOD_LUA_HS)) 118 | 119 | .PHONY: clean 120 | clean: modules-clean 121 | @rm -rf $(TARGET) 122 | 123 | .PHONY: libmod_lua libmod_lua.a libmod_lua.$(DYNAMIC_SUFFIX) 124 | libmod_lua: libmod_lua.a libmod_lua.$(DYNAMIC_SUFFIX) 125 | libmod_lua.a: $(TARGET_LIB)/libmod_lua.a 126 | libmod_lua.$(DYNAMIC_SUFFIX): $(TARGET_LIB)/libmod_lua.$(DYNAMIC_SUFFIX) 127 | 128 | ############################################################################### 129 | ## BUILD TARGETS ## 130 | ############################################################################### 131 | 132 | $(TARGET_OBJ)/%.o: $(SOURCE_MAIN)/%.c 133 | $(object) 134 | 135 | $(TARGET_LIB)/libmod_lua.$(DYNAMIC_SUFFIX): $(MOD_LUA:%=$(TARGET_OBJ)/%) | modules 136 | $(library) 137 | 138 | $(TARGET_LIB)/libmod_lua.a: $(MOD_LUA:%=$(TARGET_OBJ)/%) | modules 139 | $(archive) 140 | 141 | $(TARGET_INCL)/aerospike/%.h: $(SOURCE_INCL)/aerospike/%.h 142 | @mkdir -p $(@D) 143 | cp -p $< $@ 144 | 145 | ############################################################################### 146 | include project/modules.mk project/test.mk project/rules.mk 147 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aerospike-mod-lua 2 | 3 | Aeospike Mod Lua provides support for executing Lua language functions 4 | using the Aerospike data types. This module is used by both the 5 | Aerospike Server and the Aerospike C Client as a `git` submodule. 6 | 7 | ## Dependencies 8 | 9 | ### Linux Dependencies 10 | 11 | Building Aerospike Mod Lua requires the development resources for the 12 | Lua language version 5.4. The installation instructions for common 13 | Linux distributions are as follows: 14 | 15 | ## Build 16 | 17 | ### Build Linux and MacOS 18 | 19 | To build the test app: 20 | 21 | $ make test 22 | 23 | To build a static archive `libmod_lua.a`: 24 | 25 | $ make libmod_lua.a 26 | 27 | To build a dynamic library `libmod_lua.so`: 28 | 29 | $ make libmod_lua.so 30 | 31 | ### Build MacOS XCode 32 | 33 | - Double click xcode/aerospike-mod-lua.xcworkspace 34 | - Click Product -> Build 35 | 36 | ### Build Windows Visual Studio 2022+ 37 | 38 | - Double click vs/aerospike-mod-lua.sln 39 | - Click Build -> Build Solution 40 | 41 | ## Install 42 | 43 | All generated files are placed in `./target/{arch}`, where: 44 | 45 | - `{arch}` is the target architecture, e.g., `Linux-x86_64`. 46 | - The `lib` subdirectory contains all libraries. 47 | - The `bin` subdirectory contains all executables. 48 | 49 | #### libmod_lua.so 50 | 51 | You will want to either: 52 | 53 | 1. Move the `libmod_lua.so` to a location your program can access. 54 | 2. Add the path to `libmod_lua.so` to your `LD_LIBRARY_PATH`. 55 | 56 | ## Test 57 | 58 | To test, you can run the following: 59 | 60 | $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:target/Linux-x86_64/lib 61 | $ target/Linux-x86_64/bin/test record test1.record a b c d 62 | -------------------------------------------------------------------------------- /project/modules.mk: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | ## COMMON MODULE ## 3 | ############################################################################### 4 | 5 | ifndef COMMON 6 | $(warning ***************************************************************) 7 | $(warning *) 8 | $(warning * COMMON is not defined. ) 9 | $(warning * COMMON should be set to a valid path. ) 10 | $(warning *) 11 | $(warning ***************************************************************) 12 | $(error ) 13 | endif 14 | 15 | ifeq ($(wildcard $(COMMON)/Makefile),) 16 | $(warning ***************************************************************) 17 | $(warning *) 18 | $(warning * COMMON is '$(COMMON)') 19 | $(warning * COMMON doesn't contain 'Makefile'. ) 20 | $(warning * COMMON should be set to a valid path. ) 21 | $(warning *) 22 | $(warning ***************************************************************) 23 | $(error ) 24 | endif 25 | 26 | .PHONY: COMMON-build 27 | COMMON-build: $(COMMON)/$(TARGET_LIB)/libaerospike-common.a 28 | 29 | .PHONY: COMMON-clean 30 | COMMON-clean: 31 | $(MAKE) -e -C $(COMMON) clean 32 | 33 | $(COMMON)/$(TARGET_LIB)/libaerospike-common.a: 34 | $(MAKE) -e -C $(COMMON) libaerospike-common.a 35 | 36 | COMMON-HEADERS := $(wildcard $(COMMON)/$(TARGET_INCL)/aerospike/*.h) $(wildcard $(COMMON)/$(TARGET_INCL)/citrusleaf/*.h) 37 | 38 | .PHONY: COMMON-prepare 39 | COMMON-prepare: COMMON-make-prepare $(subst $(COMMON)/$(SOURCE_INCL),$(TARGET_INCL),$(COMMON-HEADERS)) 40 | $(noop) 41 | 42 | .PHONY: COMMON-make-prepare 43 | COMMON-make-prepare: 44 | $(MAKE) -e -C $(COMMON) prepare 45 | 46 | $(TARGET_INCL)/aerospike/%.h: $(COMMON)/$(TARGET_INCL)/aerospike/%.h 47 | @mkdir -p $(@D) 48 | cp -p $< $@ 49 | 50 | $(TARGET_INCL)/citrusleaf/%.h: $(COMMON)/$(TARGET_INCL)/citrusleaf/%.h 51 | @mkdir -p $(@D) 52 | cp -p $< $@ 53 | 54 | ############################################################################### 55 | ## LUA MODULE ## 56 | ############################################################################### 57 | 58 | ifndef LUAMOD 59 | $(warning ***************************************************************) 60 | $(warning *) 61 | $(warning * LUAMOD is not defined. ) 62 | $(warning * LUAMOD should be set to a valid path. ) 63 | $(warning *) 64 | $(warning ***************************************************************) 65 | $(error ) 66 | endif 67 | 68 | ifeq ($(wildcard $(LUAMOD)/makefile),) 69 | $(warning ***************************************************************) 70 | $(warning *) 71 | $(warning * LUAMOD is '$(LUAMOD)') 72 | $(warning * LUAMOD doesn't contain 'makefile'. ) 73 | $(warning * LUAMOD should be set to a valid path. ) 74 | $(warning *) 75 | $(warning ***************************************************************) 76 | $(error ) 77 | endif 78 | 79 | .PHONY: LUAMOD-build 80 | LUAMOD-build: $(LUAMOD)/liblua.a 81 | 82 | $(LUAMOD)/liblua.a: 83 | $(MAKE) -C $(LUAMOD) CFLAGS="-Wall -O2 -std=c99 -D$(LUA_PLATFORM) -fPIC -fno-stack-protector -fno-common $(REAL_ARCH) -g" a 84 | 85 | .PHONY: LUAMOD-clean 86 | LUAMOD-clean: 87 | $(MAKE) -e -C $(LUAMOD) clean 88 | 89 | .PHONY: LUAMOD-prepare 90 | LUAMOD-prepare: ; 91 | 92 | -------------------------------------------------------------------------------- /project/rules.mk: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | ## COMMON RULES ## 3 | ############################################################################### 4 | 5 | $(TARGET_PATH): 6 | mkdir -p $@ 7 | 8 | $(TARGET_BASE): | $(TARGET_PATH) 9 | mkdir -p $@ 10 | 11 | $(TARGET_BIN): | $(TARGET_BASE) 12 | mkdir -p $@ 13 | 14 | $(TARGET_DOC): | $(TARGET_BASE) 15 | mkdir -p $@ 16 | 17 | $(TARGET_LIB): | $(TARGET_BASE) 18 | mkdir -p $@ 19 | 20 | $(TARGET_OBJ): | $(TARGET_BASE) 21 | mkdir -p $@ 22 | 23 | $(TARGET_SRC): | $(TARGET_BASE) 24 | mkdir -p $@ 25 | 26 | $(TARGET_INCL): | $(TARGET_BASE) 27 | mkdir -p $@ 28 | 29 | .PHONY: info 30 | info: 31 | @echo 32 | @echo " NAME: " $(NAME) 33 | @echo " OS: " $(OS) 34 | @echo " ARCH: " $(ARCH) 35 | @echo " DISTRO: " $(DISTRO_NAME)"-"$(DISTRO_VERS) 36 | @echo 37 | @echo " PATHS:" 38 | @echo " source: " $(SOURCE) 39 | @echo " target: " $(TARGET_BASE) 40 | @echo " includes: " $(INC_PATH) 41 | @echo " libraries: " $(LIB_PATH) 42 | @echo 43 | @echo " COMPILER:" 44 | @echo " command: " $(CC) 45 | @echo " flags: " $(CC_FLAGS) $(CFLAGS) 46 | @echo 47 | @echo " LINKER:" 48 | @echo " command: " $(LD) 49 | @echo " flags: " $(LD_FLAGS) $(LDFLAGS) 50 | @echo 51 | @echo " ARCHIVER:" 52 | @echo " command: " $(AR) 53 | @echo " flags: " $(AR_FLAGS) $(ARFLAGS) 54 | @echo 55 | 56 | ############################################################################### 57 | ## MODULE RULES ## 58 | ############################################################################### 59 | 60 | .PHONY: modules 61 | modules: modules-build modules-prepare 62 | 63 | .PHONY: modules-build 64 | modules-build: $(MODULES:%=%-build) 65 | 66 | .PHONY: modules-prepare 67 | modules-prepare: $(MODULES:%=%-prepare) 68 | 69 | .PHONY: modules-clean 70 | modules-clean: $(MODULES:%=%-clean) 71 | -------------------------------------------------------------------------------- /project/settings.mk: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | ## BUILD VARIABLES ## 3 | ############################################################################### 4 | 5 | export CFLAGS = 6 | export LDFLAGS = 7 | export ARFLAGS = 8 | 9 | ############################################################################### 10 | ## BUILD ENVIRONMENT ## 11 | ############################################################################### 12 | 13 | ROOT = . 14 | NAME = $(shell basename $(CURDIR)) 15 | OS = $(shell uname) 16 | ARCH = $(shell uname -m) 17 | 18 | PROJECT = project 19 | MODULES = modules 20 | SOURCE = src 21 | TARGET = target 22 | LIBRARIES = 23 | 24 | ############################################################################### 25 | ## BUILD TOOLS ## 26 | ############################################################################### 27 | 28 | ifeq ($(OS),Darwin) 29 | DYNAMIC_SUFFIX=dylib 30 | DYNAMIC_FLAG=-dynamiclib 31 | else 32 | DYNAMIC_SUFFIX=so 33 | DYNAMIC_FLAG=-shared 34 | endif 35 | 36 | CC ?= cc 37 | CC_FLAGS = 38 | 39 | LD ?= cc 40 | LD_FLAGS = 41 | 42 | AR ?= ar 43 | AR_FLAGS = 44 | 45 | ############################################################################### 46 | ## SOURCE PATHS ## 47 | ############################################################################### 48 | 49 | SOURCE_PATH = $(SOURCE) 50 | SOURCE_MAIN = $(SOURCE_PATH)/main 51 | SOURCE_INCL = $(SOURCE_PATH)/include 52 | SOURCE_TEST = $(SOURCE_PATH)/test 53 | 54 | VPATH = $(SOURCE_MAIN) $(SOURCE_INCL) 55 | 56 | LIB_PATH = 57 | INC_PATH = $(SOURCE_INCL) 58 | 59 | ############################################################################### 60 | ## TARGET PATHS ## 61 | ############################################################################### 62 | 63 | ifeq ($(shell test -e $(PROJECT)/target.$(DISTRO_NAME)-$(DISTRO_VERS)-$(ARCH).makefile && echo 1), 1) 64 | PLATFORM = $(DISTRO_NAME)-$(DISTRO_VERS)-$(ARCH) 65 | include $(PROJECT)/target.$(PLATFORM).makefile 66 | else 67 | ifeq ($(shell test -e $(PROJECT)/target.$(DISTRO_NAME)-$(ARCH).makefile && echo 1), 1) 68 | PLATFORM = $(DISTRO_NAME)-$(ARCH) 69 | include $(PROJECT)/target.$(PLATFORM).makefile 70 | else 71 | ifeq ($(shell test -e $(PROJECT)/target.$(OS)-$(ARCH).makefile && echo 1), 1) 72 | PLATFORM = $(OS)-$(ARCH) 73 | include $(PROJECT)/target.$(PLATFORM).makefile 74 | else 75 | ifeq ($(shell test -e project/target.$(OS)-noarch.makefile && echo 1), 1) 76 | PLATFORM = $(OS)-noarch 77 | include $(PROJECT)/target.$(PLATFORM).makefile 78 | else 79 | PLATFORM = $(OS)-$(ARCH) 80 | endif 81 | endif 82 | endif 83 | endif 84 | 85 | TARGET_PATH = $(TARGET) 86 | TARGET_BASE = $(TARGET_PATH)/$(PLATFORM) 87 | TARGET_BIN = $(TARGET_BASE)/bin 88 | TARGET_DOC = $(TARGET_BASE)/doc 89 | TARGET_LIB = $(TARGET_BASE)/lib 90 | TARGET_OBJ = $(TARGET_BASE)/obj 91 | TARGET_M4 = $(TARGET_BASE)/m4 92 | TARGET_SRC = $(TARGET_BASE)/src 93 | TARGET_INCL = $(TARGET_BASE)/include 94 | 95 | ############################################################################### 96 | ## FUNCTIONS ## 97 | ############################################################################### 98 | 99 | define executable 100 | @if [ ! -d `dirname $@` ]; then mkdir -p `dirname $@`; fi 101 | $(strip $(CC) \ 102 | $(addprefix -I, $(INC_PATH)) \ 103 | $(addprefix -L, $(LIB_PATH)) \ 104 | $(addprefix -l, $(LIBRARIES)) \ 105 | $(CC_FLAGS) \ 106 | $(CFLAGS) \ 107 | -o $@ \ 108 | $(filter %.o %.a %.so, $^) \ 109 | $(LD_FLAGS) \ 110 | ) 111 | endef 112 | 113 | define archive 114 | @if [ ! -d `dirname $@` ]; then mkdir -p `dirname $@`; fi 115 | $(strip $(AR) \ 116 | rcs \ 117 | $(AR_FLAGS) \ 118 | $(ARFLAGS) \ 119 | $@ \ 120 | $(filter %.o, $^) \ 121 | ) 122 | endef 123 | 124 | define library 125 | @if [ ! -d `dirname $@` ]; then mkdir -p `dirname $@`; fi 126 | $(strip $(CC) $(DYNAMIC_FLAG) \ 127 | $(addprefix -I, $(INC_PATH)) \ 128 | $(addprefix -L, $(LIB_PATH)) \ 129 | $(addprefix -l, $(LIBRARIES)) \ 130 | $(LD_FLAGS) \ 131 | $(LDFLAGS) \ 132 | -o $@ \ 133 | $(filter %.o, $^) \ 134 | ) 135 | endef 136 | 137 | define object 138 | @if [ ! -d `dirname $@` ]; then mkdir -p `dirname $@`; fi 139 | $(strip $(CC) \ 140 | $(addprefix -I, $(INC_PATH)) \ 141 | $(addprefix -L, $(LIB_PATH)) \ 142 | $(CC_FLAGS) \ 143 | $(CFLAGS) \ 144 | -o $@ \ 145 | -c $(filter %.c %.cpp, $^) \ 146 | ) 147 | endef 148 | -------------------------------------------------------------------------------- /project/test.mk: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | ## TEST FLAGS ## 3 | ############################################################################### 4 | 5 | TEST_VALGRIND = --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes -v 6 | 7 | TEST_CFLAGS = 8 | TEST_CFLAGS += -I$(TARGET_INCL) 9 | TEST_CFLAGS += -I$(COMMON)/$(TARGET_INCL) 10 | TEST_CFLAGS += -I$(LUAMOD) 11 | 12 | TEST_LDFLAGS = 13 | 14 | ifeq ($(OS),Darwin) 15 | ifneq ($(wildcard /opt/homebrew/opt/openssl/lib),) 16 | # Mac new homebrew openssl lib path 17 | TEST_LDFLAGS += -L/opt/homebrew/opt/openssl/lib 18 | endif 19 | endif 20 | 21 | TEST_LDFLAGS += -lssl -lcrypto -lpthread -lm 22 | 23 | ifeq ($(OS),FreeBSD) 24 | TEST_LDFLAGS += -lrt 25 | else ifneq ($(OS),Darwin) 26 | TEST_LDFLAGS += -lrt -ldl 27 | endif 28 | 29 | TEST_DEPS = 30 | TEST_DEPS += $(COMMON)/$(TARGET_LIB)/libaerospike-common.a 31 | TEST_DEPS += $(LUAMOD)/liblua.a 32 | TEST_DEPS += $(TARGET_LIB)/libmod_lua.a 33 | 34 | ############################################################################### 35 | ## TEST OBJECTS ## 36 | ############################################################################### 37 | 38 | TEST_PLANS = 39 | TEST_PLANS += list/list_udf 40 | TEST_PLANS += record/record_udf 41 | TEST_PLANS += stream/stream_udf 42 | TEST_PLANS += validation/validation_basics 43 | TEST_PLANS += hash/hash_udf 44 | 45 | TEST_UTIL = 46 | TEST_UTIL += util/consumer_stream 47 | TEST_UTIL += util/producer_stream 48 | TEST_UTIL += util/map_rec 49 | TEST_UTIL += util/test_aerospike 50 | TEST_UTIL += util/test_logger 51 | #TEST_UTIL += util/test_memtracker 52 | 53 | TEST_MOD_LUA = mod_lua_test 54 | TEST_MOD_LUA += $(TEST_UTIL) 55 | TEST_MOD_LUA += $(TEST_PLANS) 56 | 57 | ############################################################################### 58 | ## TEST TARGETS ## 59 | ############################################################################### 60 | 61 | .PHONY: test 62 | test: test-build 63 | $(TARGET_BIN)/test/mod_lua_test 64 | 65 | .PHONY: test-valgrind 66 | test-valgrind: test-build 67 | valgrind $(TEST_VALGRIND) $(TARGET_BIN)/test/mod_lua_test 1>&2 2>mod_lua_test-valgrind 68 | 69 | .PHONY: test-build 70 | test-build: $(TEST_DEPS) test/mod_lua_test 71 | 72 | .PHONY: test-clean 73 | test-clean: 74 | @rm -rf $(TARGET_BIN)/test 75 | @rm -rf $(TARGET_OBJ)/test 76 | 77 | $(TARGET_OBJ)/test/%/%.o: CFLAGS = $(TEST_CFLAGS) 78 | $(TARGET_OBJ)/test/%/%.o: LDFLAGS = $(TEST_LDFLAGS) 79 | $(TARGET_OBJ)/test/%/%.o: $(SOURCE_TEST)/%/%.c 80 | $(object) 81 | 82 | $(TARGET_OBJ)/test/%.o: CFLAGS = $(TEST_CFLAGS) 83 | $(TARGET_OBJ)/test/%.o: LDFLAGS = $(TEST_LDFLAGS) 84 | $(TARGET_OBJ)/test/%.o: $(SOURCE_TEST)/%.c 85 | $(object) 86 | 87 | .PHONY: test/mod_lua_test 88 | test/mod_lua_test: $(TARGET_BIN)/test/mod_lua_test 89 | $(TARGET_BIN)/test/mod_lua_test: CFLAGS = $(TEST_CFLAGS) 90 | $(TARGET_BIN)/test/mod_lua_test: LDFLAGS = $(TEST_DEPS) $(TEST_LDFLAGS) 91 | $(TARGET_BIN)/test/mod_lua_test: $(TEST_MOD_LUA:%=$(TARGET_OBJ)/test/%.o) $(TARGET_OBJ)/test/test.o $(wildcard $(TARGET_OBJ)/*) | modules build prepare 92 | $(executable) 93 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | /** 22 | * Lua Module 23 | */ 24 | extern as_module mod_lua; 25 | 26 | 27 | /** 28 | * Locks 29 | */ 30 | void mod_lua_rdlock(as_module* m); 31 | void mod_lua_wrlock(as_module* m); 32 | void mod_lua_unlock(as_module* m); 33 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_aerospike.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | int mod_lua_aerospike_register(lua_State *); 25 | 26 | as_aerospike * mod_lua_pushaerospike(lua_State *, as_aerospike * ); 27 | 28 | as_aerospike * mod_lua_toaerospike(lua_State *, int); 29 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_bytes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | int mod_lua_bytes_register(lua_State *); 25 | 26 | as_bytes * mod_lua_pushbytes(lua_State *, as_bytes * ); 27 | 28 | as_bytes * mod_lua_tobytes(lua_State *, int); 29 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | /***************************************************************************** 22 | * TYPES 23 | *****************************************************************************/ 24 | 25 | struct mod_lua_config_s; 26 | typedef struct mod_lua_config_s mod_lua_config; 27 | 28 | struct mod_lua_config_s { 29 | bool server_mode; 30 | bool cache_enabled; 31 | char user_path[256]; 32 | }; 33 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_geojson.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | int mod_lua_geojson_register(lua_State *); 25 | 26 | as_geojson * mod_lua_pushgeojson(lua_State *, as_geojson * ); 27 | 28 | as_geojson * mod_lua_togeojson(lua_State *, int); 29 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | int mod_lua_iterator_register(lua_State *); 23 | 24 | // Pushes an iterator userdata object, and returns that 25 | // object so it can be initialized 26 | // (works different than some of the other calls) 27 | as_iterator * mod_lua_pushiterator(lua_State *, size_t sz); 28 | 29 | as_iterator * mod_lua_toiterator(lua_State *, int); 30 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | int mod_lua_list_register(lua_State *); 25 | 26 | as_list * mod_lua_pushlist(lua_State *, as_list * ); 27 | 28 | as_list * mod_lua_tolist(lua_State *, int); 29 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int mod_lua_map_register(lua_State *); 24 | 25 | as_map * mod_lua_pushmap(lua_State *, as_map * ); 26 | 27 | as_map * mod_lua_tomap(lua_State *, int); 28 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_record.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | int mod_lua_record_register(lua_State *); 25 | 26 | as_rec * mod_lua_pushrecord(lua_State *, as_rec * ); 27 | 28 | as_rec * mod_lua_torecord(lua_State *, int); 29 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_reg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | 26 | /** 27 | * Registers an Object 28 | * An Object is a Lua Table that is not bound to userdata. 29 | */ 30 | int mod_lua_reg_object(lua_State *, const char *, const luaL_Reg *, const luaL_Reg *); 31 | 32 | /** 33 | * Registers a Class 34 | * A Class is a Lua Table that is bound to userdata. 35 | */ 36 | int mod_lua_reg_class(lua_State *, const char *, const luaL_Reg *, const luaL_Reg *); 37 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | int mod_lua_stream_register(lua_State *); 23 | 24 | as_stream * mod_lua_pushstream(lua_State *, as_stream *); 25 | 26 | as_stream * mod_lua_tostream(lua_State *, int); 27 | -------------------------------------------------------------------------------- /src/include/aerospike/mod_lua_val.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | typedef struct mod_lua_box_s mod_lua_box; 26 | 27 | typedef enum { 28 | MOD_LUA_SCOPE_LUA, // The value can be freed by Lua 29 | MOD_LUA_SCOPE_HOST // The value must not be freed by Lua 30 | } mod_lua_scope; 31 | 32 | struct mod_lua_box_s { 33 | mod_lua_scope scope; 34 | void * value; 35 | }; 36 | 37 | as_val * mod_lua_takeval(lua_State * l, int i); 38 | as_val * mod_lua_retval(lua_State * l); 39 | as_val * mod_lua_toval(lua_State *, int); 40 | int mod_lua_pushval(lua_State *, const as_val *); 41 | 42 | mod_lua_box * mod_lua_newbox(lua_State *, mod_lua_scope, void *, const char *); 43 | mod_lua_box * mod_lua_pushbox(lua_State *, mod_lua_scope, void *, const char *); 44 | mod_lua_box * mod_lua_tobox(lua_State *, int, const char *); 45 | mod_lua_box * mod_lua_checkbox(lua_State *, int, const char *); 46 | int mod_lua_freebox(lua_State *, int, const char *); 47 | void * mod_lua_box_value(mod_lua_box *); 48 | -------------------------------------------------------------------------------- /src/main/internal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include "internal.h" 22 | 23 | void __log_append(const char * file, int line, const char * fmt, ...) { 24 | char msg[1024] = {0}; 25 | va_list ap; 26 | va_start(ap, fmt); 27 | vsnprintf(msg, 1024, fmt, ap); 28 | va_end(ap); 29 | printf("%s:%d – %s\n",file,line,msg); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | struct lua_State; 24 | 25 | // 26 | // logging 27 | // 28 | 29 | #define LOG(fmt, ...) \ 30 | // __log_append(__FILE__, __LINE__, fmt, ##__VA_ARGS__); 31 | 32 | void __log_append(const char * file, int line, const char * fmt, ...); 33 | 34 | // A copy of luaL_typerror which was dropped in lua-5.3. 35 | static inline int 36 | mod_lua_typerror(struct lua_State *L, int narg, const char *tname) 37 | { 38 | const char *msg = lua_pushfstring(L, "%s expected, got %s", 39 | tname, luaL_typename(L, narg)); 40 | return luaL_argerror(L, narg, msg); 41 | } 42 | 43 | #define DO_PRAGMA(x) _Pragma (#x) 44 | #define TODO(x) DO_PRAGMA(message ("TODO - " #x)) 45 | -------------------------------------------------------------------------------- /src/main/mod_lua_aerospike.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "internal.h" 27 | 28 | 29 | /******************************************************************************* 30 | * MACROS 31 | ******************************************************************************/ 32 | 33 | #define CLASS_NAME "Aerospike" 34 | 35 | /******************************************************************************* 36 | * FUNCTIONS 37 | ******************************************************************************/ 38 | 39 | /** 40 | * Read the item at index and convert to a aerospike 41 | */ 42 | as_aerospike * mod_lua_toaerospike(lua_State * l, int index) { 43 | mod_lua_box * box = mod_lua_tobox(l, index, CLASS_NAME); 44 | return (as_aerospike *) mod_lua_box_value(box); 45 | } 46 | 47 | /** 48 | * Push aerospike on to the lua stack 49 | */ 50 | as_aerospike * mod_lua_pushaerospike(lua_State * l, as_aerospike * a) { 51 | mod_lua_box * box = mod_lua_pushbox(l, MOD_LUA_SCOPE_HOST, a, CLASS_NAME); 52 | return (as_aerospike *) mod_lua_box_value(box); 53 | } 54 | 55 | /** 56 | * Get aerospike from the stack at index 57 | */ 58 | static as_aerospike * mod_lua_checkaerospike(lua_State * l, int index) { 59 | mod_lua_box * box = mod_lua_checkbox(l, index, CLASS_NAME); 60 | return (as_aerospike *) mod_lua_box_value(box); 61 | } 62 | 63 | /** 64 | * Garbage collection 65 | */ 66 | static int mod_lua_aerospike_gc(lua_State * l) { 67 | LOG("mod_lua_aerospike_gc: begin"); 68 | mod_lua_freebox(l, 1, CLASS_NAME); 69 | LOG("mod_lua_aerospike_gc: end"); 70 | return 0; 71 | } 72 | 73 | 74 | /** 75 | * aerospike.create(record) => result 76 | */ 77 | static int mod_lua_aerospike_rec_create(lua_State * l) { 78 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 79 | as_rec * r = mod_lua_torecord(l, 2); 80 | int rc = as_aerospike_rec_create(a, r); 81 | lua_pushinteger(l, rc); 82 | return 1; 83 | } 84 | 85 | /** 86 | * aerospike.update(record) => result 87 | */ 88 | static int mod_lua_aerospike_rec_update(lua_State * l) { 89 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 90 | as_rec * r = mod_lua_torecord(l, 2); 91 | int rc = as_aerospike_rec_update(a, r); 92 | lua_pushinteger(l, rc); 93 | return 1; 94 | } 95 | 96 | /** 97 | * aerospike.exists(record) => result 98 | */ 99 | static int mod_lua_aerospike_rec_exists(lua_State * l) { 100 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 101 | as_rec * r = mod_lua_torecord(l, 2); 102 | int rc = as_aerospike_rec_exists(a, r); 103 | lua_pushboolean(l, rc == 1); 104 | return 1; 105 | } 106 | 107 | /** 108 | * aerospike.remove(namespace, set, key) => result 109 | */ 110 | static int mod_lua_aerospike_rec_remove(lua_State * l) { 111 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 112 | as_rec * r = mod_lua_torecord(l, 2); 113 | int rc = as_aerospike_rec_remove(a, r); 114 | lua_pushinteger(l, rc); 115 | return 1; 116 | } 117 | 118 | /** 119 | * aerospike.log(level, message) 120 | */ 121 | static int mod_lua_aerospike_log(lua_State * l) { 122 | lua_Debug ar; 123 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 124 | int lvl = (int)luaL_optinteger(l, 2, 0); 125 | const char * msg = luaL_optstring(l, 3, NULL); 126 | 127 | lua_getstack(l, 2, &ar); 128 | 129 | lua_getinfo(l, "nSl", &ar); 130 | 131 | as_aerospike_log(a, ++ar.source, ar.currentline, lvl, msg); 132 | return 0; 133 | } // end mod_lua_aerospike_log() 134 | 135 | /** 136 | * Compute the time and store it in Lua. We will have to decide what type 137 | * we want to use for that -- since Lua numbers are only 56 bits precision, 138 | * and cf_clock is a 64 bit value. 139 | * It is possible that we'll have to store this as BYTES (similar to how we 140 | * deal with digests) -- or something. 141 | */ 142 | static int mod_lua_aerospike_get_current_time(lua_State * l) { 143 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 144 | cf_clock cur_time = as_aerospike_get_current_time( a ); 145 | lua_pushinteger(l, cur_time ); // May have to push some other type @TOBY 146 | return 1; 147 | } 148 | 149 | /** 150 | * Hook to set execution context information 151 | */ 152 | static int mod_lua_aerospike_set_context(lua_State * l) { 153 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 154 | 155 | as_rec * r = mod_lua_torecord(l, 2); 156 | 157 | // Get the 2nd arg off the stack -- and process as context 158 | uint32_t context = (uint32_t)luaL_optinteger(l, 3, 0); 159 | 160 | int ret = as_aerospike_set_context(a, r, context); 161 | 162 | lua_pushinteger(l, ret); 163 | return 1; 164 | } 165 | 166 | /** 167 | * hook to fetch config information from server. 168 | */ 169 | static int mod_lua_aerospike_get_config(lua_State * l) { 170 | as_aerospike * a = mod_lua_checkaerospike(l, 1); 171 | as_rec * r = mod_lua_torecord(l, 2); 172 | const char * name = luaL_optstring(l, 3, NULL); 173 | 174 | int ret = as_aerospike_get_config(a, r, name); 175 | lua_pushinteger(l, ret); 176 | return 1; 177 | } // end mod_lua_aerospike_get_config() 178 | 179 | /****************************************************************************** 180 | * CLASS TABLE 181 | *****************************************************************************/ 182 | 183 | static const luaL_Reg class_table[] = { 184 | {"create", mod_lua_aerospike_rec_create}, 185 | {"update", mod_lua_aerospike_rec_update}, 186 | {"exists", mod_lua_aerospike_rec_exists}, 187 | {"remove", mod_lua_aerospike_rec_remove}, 188 | {"log", mod_lua_aerospike_log}, 189 | {"get_current_time", mod_lua_aerospike_get_current_time}, 190 | {"set_context", mod_lua_aerospike_set_context}, 191 | {"get_config", mod_lua_aerospike_get_config}, 192 | {0, 0} 193 | }; 194 | 195 | static const luaL_Reg class_metatable[] = { 196 | {"__gc", mod_lua_aerospike_gc}, 197 | {0, 0} 198 | }; 199 | 200 | /****************************************************************************** 201 | * REGISTER 202 | *****************************************************************************/ 203 | 204 | int mod_lua_aerospike_register(lua_State * l) { 205 | mod_lua_reg_class(l, CLASS_NAME, class_table, class_metatable); 206 | return 1; 207 | } 208 | -------------------------------------------------------------------------------- /src/main/mod_lua_geojson.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "internal.h" 26 | 27 | /******************************************************************************* 28 | * MACROS 29 | ******************************************************************************/ 30 | 31 | #define OBJECT_NAME "geojson" 32 | #define CLASS_NAME "GeoJSON" 33 | 34 | /******************************************************************************* 35 | * BOX FUNCTIONS 36 | ******************************************************************************/ 37 | 38 | as_geojson * mod_lua_togeojson(lua_State * l, int index) { 39 | mod_lua_box * box = mod_lua_tobox(l, index, CLASS_NAME); 40 | return (as_geojson *) mod_lua_box_value(box); 41 | } 42 | 43 | as_geojson * mod_lua_pushgeojson(lua_State * l, as_geojson * b) { 44 | mod_lua_box * box = mod_lua_pushbox(l, MOD_LUA_SCOPE_LUA, b, CLASS_NAME); 45 | return (as_geojson *) mod_lua_box_value(box); 46 | } 47 | 48 | #if 0 49 | static as_geojson * mod_lua_checkgeojson(lua_State * l, int index) { 50 | mod_lua_box * box = mod_lua_checkbox(l, index, CLASS_NAME); 51 | return (as_geojson *) mod_lua_box_value(box); 52 | } 53 | #endif 54 | 55 | static int mod_lua_geojson_gc(lua_State * l) { 56 | mod_lua_freebox(l, 1, CLASS_NAME); 57 | return 0; 58 | } 59 | 60 | /******************************************************************************* 61 | * FUNCTIONS 62 | ******************************************************************************/ 63 | 64 | static int mod_lua_geojson_new(lua_State * l) 65 | { 66 | int argc = lua_gettop(l); 67 | if (argc != 2) { 68 | return 0; 69 | } 70 | 71 | const char * geostr = luaL_optstring(l, 2, NULL); 72 | if (geostr == NULL) { 73 | return 0; 74 | } 75 | 76 | as_geojson * geo = as_geojson_new(cf_strdup(geostr), true); 77 | if (geo == NULL) { 78 | return 0; 79 | } 80 | 81 | mod_lua_pushgeojson(l, geo); 82 | return 1; 83 | } 84 | 85 | static int mod_lua_geojson_tostring(lua_State * l) 86 | { 87 | // we expect 1 arg 88 | if ( lua_gettop(l) != 1 ) { 89 | lua_pushinteger(l, 0); 90 | return 1; 91 | } 92 | 93 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 94 | as_val * val = mod_lua_box_value(box); 95 | char * str = NULL; 96 | 97 | if ( val ) { 98 | str = as_val_tostring(val); 99 | } 100 | 101 | if ( str ) { 102 | lua_pushstring(l, str); 103 | cf_free(str); 104 | } 105 | else { 106 | lua_pushstring(l, "GeoJSON()"); 107 | } 108 | 109 | return 1; 110 | } 111 | 112 | /****************************************************************************** 113 | * OBJECT TABLE 114 | *****************************************************************************/ 115 | 116 | static const luaL_Reg geojson_object_table[] = { 117 | {0, 0} 118 | }; 119 | 120 | static const luaL_Reg geojson_object_metatable[] = { 121 | {"__call", mod_lua_geojson_new}, 122 | {0, 0} 123 | }; 124 | 125 | /****************************************************************************** 126 | * CLASS TABLE 127 | *****************************************************************************/ 128 | 129 | static const luaL_Reg geojson_class_metatable[] = { 130 | {"__tostring", mod_lua_geojson_tostring}, 131 | {"__gc", mod_lua_geojson_gc}, 132 | {0, 0} 133 | }; 134 | 135 | /****************************************************************************** 136 | * REGISTER 137 | *****************************************************************************/ 138 | 139 | int mod_lua_geojson_register(lua_State * l) { 140 | mod_lua_reg_object(l, OBJECT_NAME, 141 | geojson_object_table, geojson_object_metatable); 142 | mod_lua_reg_class(l, CLASS_NAME, NULL, geojson_class_metatable); 143 | return 1; 144 | } 145 | -------------------------------------------------------------------------------- /src/main/mod_lua_iterator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "internal.h" 27 | 28 | /******************************************************************************* 29 | * MACROS 30 | ******************************************************************************/ 31 | 32 | #define OBJECT_NAME "iterator" 33 | #define CLASS_NAME "Iterator" 34 | 35 | /******************************************************************************* 36 | * FUNCTIONS 37 | ******************************************************************************/ 38 | 39 | // 40 | // NOTE ITERATORS ARE NOT AS_VALS 41 | // 42 | 43 | as_iterator * mod_lua_toiterator(lua_State * l, int index) { 44 | as_iterator * itr = (as_iterator *) lua_touserdata(l, index); 45 | return (as_iterator *) itr; 46 | } 47 | 48 | as_iterator * mod_lua_pushiterator(lua_State * l, size_t sz) { 49 | as_iterator * i = (as_iterator *) lua_newuserdata(l, sz); 50 | memset(i, 0, sz); 51 | luaL_getmetatable(l, CLASS_NAME); 52 | lua_setmetatable(l, -2); 53 | return i; 54 | } 55 | 56 | static as_iterator * mod_lua_checkiterator(lua_State * l, int index) { 57 | luaL_checktype(l, index, LUA_TUSERDATA); 58 | as_iterator * itr = (as_iterator *) luaL_checkudata(l, index, CLASS_NAME); 59 | if (itr == NULL) mod_lua_typerror(l, index, CLASS_NAME); 60 | return itr; 61 | } 62 | 63 | static int mod_lua_iterator_gc(lua_State * l) { 64 | as_iterator * itr = (as_iterator *) lua_touserdata(l, 1); 65 | if (itr) as_iterator_destroy(itr); 66 | return 0; 67 | } 68 | 69 | /** 70 | * Tests to see if there are any more entries in the iterator 71 | */ 72 | static int mod_lua_iterator_has_next(lua_State * l) { 73 | as_iterator * i = mod_lua_checkiterator(l, 1); 74 | bool b = as_iterator_has_next(i); 75 | lua_pushboolean(l, b); 76 | return 1; 77 | } 78 | 79 | /** 80 | * Tests to see if there are any more entries in the iterator 81 | */ 82 | static int mod_lua_iterator_next(lua_State * l) { 83 | as_iterator * i = mod_lua_checkiterator(l, 1); 84 | as_val * v = (as_val *) as_iterator_next(i); 85 | if ( v != NULL ) { 86 | mod_lua_pushval(l,v); 87 | } 88 | else { 89 | lua_pushnil(l); 90 | } 91 | return 1; 92 | } 93 | 94 | 95 | /****************************************************************************** 96 | * OBJECT TABLE 97 | *****************************************************************************/ 98 | 99 | static const luaL_Reg object_table[] = { 100 | {"has_next", mod_lua_iterator_has_next}, 101 | {"next", mod_lua_iterator_next}, 102 | {0, 0} 103 | }; 104 | 105 | static const luaL_Reg object_metatable[] = { 106 | {"__call", mod_lua_iterator_next}, 107 | {0, 0} 108 | }; 109 | 110 | /****************************************************************************** 111 | * CLASS TABLE 112 | *****************************************************************************/ 113 | 114 | static const luaL_Reg class_table[] = { 115 | {"has_next", mod_lua_iterator_has_next}, 116 | {"next", mod_lua_iterator_next}, 117 | {0, 0} 118 | }; 119 | 120 | static const luaL_Reg class_metatable[] = { 121 | {"__gc", mod_lua_iterator_gc}, 122 | {0, 0} 123 | }; 124 | 125 | /****************************************************************************** 126 | * REGISTER 127 | *****************************************************************************/ 128 | 129 | int mod_lua_iterator_register(lua_State * l) { 130 | mod_lua_reg_object(l, OBJECT_NAME, object_table, object_metatable); 131 | mod_lua_reg_class(l, CLASS_NAME, class_table, class_metatable); 132 | return 1; 133 | } 134 | 135 | -------------------------------------------------------------------------------- /src/main/mod_lua_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2024 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "internal.h" 28 | 29 | /******************************************************************************* 30 | * MACROS 31 | ******************************************************************************/ 32 | 33 | #define OBJECT_NAME "map" 34 | #define CLASS_NAME "Map" 35 | 36 | /******************************************************************************* 37 | * FUNCTIONS 38 | ******************************************************************************/ 39 | 40 | as_map * mod_lua_tomap(lua_State * l, int index) { 41 | mod_lua_box * box = mod_lua_tobox(l, index, CLASS_NAME); 42 | return (as_map *) mod_lua_box_value(box); 43 | } 44 | 45 | as_map * mod_lua_pushmap(lua_State * l, as_map * map) { 46 | mod_lua_box * box = mod_lua_pushbox(l, MOD_LUA_SCOPE_LUA, map, CLASS_NAME); 47 | return (as_map *) mod_lua_box_value(box); 48 | } 49 | 50 | static as_map * mod_lua_checkmap(lua_State * l, int index) { 51 | mod_lua_box * box = mod_lua_checkbox(l, index, CLASS_NAME); 52 | return (as_map *) mod_lua_box_value(box); 53 | } 54 | 55 | static int mod_lua_map_gc(lua_State * l) { 56 | mod_lua_freebox(l, 1, CLASS_NAME); 57 | return 0; 58 | } 59 | 60 | 61 | 62 | static int mod_lua_map_size(lua_State * l) { 63 | as_map * map = mod_lua_checkmap(l, 1); 64 | uint32_t size = as_map_size(map); 65 | lua_pushinteger(l, size); 66 | return 1; 67 | } 68 | 69 | static int mod_lua_map_nbytes(lua_State * l) { 70 | as_map * map = mod_lua_checkmap(l, 1); 71 | uint32_t nbytes = 0; 72 | if ( map ) { 73 | as_serializer s; 74 | as_msgpack_init(&s); 75 | nbytes = as_serializer_serialize_getsize(&s, (as_val *) map); 76 | as_serializer_destroy(&s); 77 | } 78 | lua_pushinteger(l, nbytes); 79 | return 1; 80 | } 81 | 82 | static int mod_lua_map_new(lua_State * l) { 83 | int n = lua_gettop(l); 84 | if (n != 1) { 85 | return 0; 86 | } 87 | lua_Integer capacity = luaL_optinteger(l, 1, 0); 88 | if (capacity < 1) { 89 | return 0; 90 | } 91 | as_map * map = (as_map *) as_hashmap_new((uint32_t)capacity); 92 | mod_lua_pushmap(l, map); 93 | return 1; 94 | } 95 | 96 | static int mod_lua_map_cons(lua_State * l) { 97 | lua_Integer capacity = luaL_optinteger(l, 3, 32); 98 | if (capacity < 1) { 99 | capacity = 32; 100 | } 101 | as_map * map = (as_map *) as_hashmap_new((uint32_t)capacity); 102 | int n = lua_gettop(l); 103 | if ( (n == 2 || n == 3) && lua_type(l, 2) == LUA_TTABLE ) { 104 | lua_pushnil(l); 105 | while ( lua_next(l, 2) != 0 ) { 106 | // this will leak or crash if these are not as_val, or k is and v isn't 107 | as_val * k = mod_lua_takeval(l, -2); 108 | as_val * v = mod_lua_takeval(l, -1); 109 | if ( !k || !v || as_map_set(map, k, v) != 0) { 110 | as_val_destroy(k); 111 | as_val_destroy(v); 112 | } 113 | lua_pop(l, 1); 114 | } 115 | } 116 | mod_lua_pushmap(l, map); 117 | return 1; 118 | } 119 | 120 | static int mod_lua_map_index(lua_State * l) { 121 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 122 | as_map * map = (as_map *) mod_lua_box_value(box); 123 | as_val * val = NULL; 124 | 125 | if ( map ) { 126 | as_val * key = mod_lua_takeval(l, 2); 127 | if ( key ) { 128 | val = as_map_get(map, key); 129 | as_val_destroy(key); 130 | } 131 | } 132 | 133 | if ( val ) { 134 | mod_lua_pushval(l, val); 135 | } 136 | else { 137 | lua_pushnil(l); 138 | } 139 | 140 | return 1; 141 | } 142 | 143 | static int mod_lua_map_newindex(lua_State * l) { 144 | as_map * map = mod_lua_checkmap(l, 1); 145 | if ( map ) { 146 | as_val * key = mod_lua_takeval(l, 2); 147 | as_val * val = mod_lua_takeval(l, 3); 148 | if ( !key || as_val_type(val) == AS_REC ) { 149 | as_val_destroy(key); 150 | as_val_destroy(val); 151 | } 152 | else if ( !val ) { 153 | as_map_remove(map, key); 154 | as_val_destroy(key); 155 | } 156 | else if (as_map_set(map, key, val) != 0) { 157 | as_val_destroy(key); 158 | as_val_destroy(val); 159 | } 160 | } 161 | return 0; 162 | } 163 | 164 | static int mod_lua_map_remove(lua_State * l) { 165 | as_map * map = mod_lua_checkmap(l, 1); 166 | if ( map ) { 167 | as_val * key = mod_lua_takeval(l, 2); 168 | if ( key ) { 169 | as_map_remove(map, key); 170 | as_val_destroy(key); 171 | } 172 | } 173 | return 0; 174 | } 175 | 176 | static int mod_lua_map_len(lua_State * l) { 177 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 178 | as_map * map = (as_map *) mod_lua_box_value(box); 179 | if ( map ) { 180 | lua_pushinteger(l, as_map_size(map)); 181 | } 182 | else { 183 | lua_pushinteger(l, 0); 184 | } 185 | return 1; 186 | } 187 | 188 | static int mod_lua_map_tostring(lua_State * l) { 189 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 190 | as_val * val = mod_lua_box_value(box); 191 | char * str = NULL; 192 | 193 | if ( val ) { 194 | str = as_val_tostring(val); 195 | } 196 | 197 | if ( str ) { 198 | lua_pushstring(l, str); 199 | cf_free(str); 200 | } 201 | else { 202 | lua_pushstring(l, "Map()"); 203 | } 204 | 205 | return 1; 206 | } 207 | 208 | /** 209 | * Generator for map.pairs() 210 | */ 211 | static int mod_lua_map_pairs_next(lua_State * l) { 212 | as_iterator * iter = mod_lua_toiterator(l, 1); 213 | if ( iter && as_iterator_has_next(iter) ) { 214 | as_pair * pair = (as_pair *) as_iterator_next(iter); 215 | if ( pair ) { 216 | mod_lua_pushval(l, pair->_1); 217 | mod_lua_pushval(l, pair->_2); 218 | return 2; 219 | } 220 | } 221 | return 0; 222 | } 223 | 224 | /** 225 | * USAGE: 226 | * for k,v in map.pairs(m) do 227 | * end 228 | * USAGE: 229 | * for k,v in map.iterator(m) do 230 | * end 231 | */ 232 | static int mod_lua_map_pairs(lua_State * l) { 233 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 234 | as_map * map = (as_map *) mod_lua_box_value(box); 235 | if ( map ) { 236 | lua_pushcfunction(l, mod_lua_map_pairs_next); 237 | as_map_iterator * itr = (as_map_iterator *) mod_lua_pushiterator(l, sizeof(as_map_iterator)); 238 | as_map_iterator_init(itr,map); 239 | return 2; 240 | } 241 | 242 | return 0; 243 | } 244 | 245 | /** 246 | * Generator for map.keys() 247 | */ 248 | static int mod_lua_map_keys_next(lua_State * l) { 249 | as_iterator * iter = mod_lua_toiterator(l, 1); 250 | if ( iter && as_iterator_has_next(iter) ) { 251 | as_pair * pair = (as_pair *) as_iterator_next(iter); 252 | if ( pair ) { 253 | mod_lua_pushval(l, pair->_1); 254 | return 1; 255 | } 256 | } 257 | return 0; 258 | } 259 | 260 | /** 261 | * USAGE: 262 | * for k in map.keys(m) do 263 | * end 264 | */ 265 | static int mod_lua_map_keys(lua_State * l) { 266 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 267 | as_map * map = (as_map *) mod_lua_box_value(box); 268 | if ( map ) { 269 | lua_pushcfunction(l, mod_lua_map_keys_next); 270 | as_map_iterator * iter = (as_map_iterator *) mod_lua_pushiterator(l, sizeof(as_map_iterator)); 271 | as_map_iterator_init(iter, map); 272 | return 2; 273 | } 274 | 275 | return 0; 276 | } 277 | 278 | /** 279 | * Generator for map.values() 280 | */ 281 | static int mod_lua_map_values_next(lua_State * l) { 282 | as_iterator * iter = mod_lua_toiterator(l, 1); 283 | if ( iter && as_iterator_has_next(iter) ) { 284 | as_pair * pair = (as_pair *) as_iterator_next(iter); 285 | if ( pair ) { 286 | mod_lua_pushval(l, pair->_2); 287 | return 1; 288 | } 289 | } 290 | return 0; 291 | } 292 | 293 | /** 294 | * USAGE: 295 | * for v in map.values(m) do 296 | * end 297 | */ 298 | static int mod_lua_map_values(lua_State * l) { 299 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 300 | as_map * map = (as_map *) mod_lua_box_value(box); 301 | if ( map ) { 302 | lua_pushcfunction(l, mod_lua_map_values_next); 303 | as_map_iterator * itr = (as_map_iterator *) mod_lua_pushiterator(l, sizeof(as_map_iterator)); 304 | as_map_iterator_init(itr, map); 305 | return 2; 306 | } 307 | 308 | return 0; 309 | } 310 | 311 | /****************************************************************************** 312 | * OBJECT TABLE 313 | *****************************************************************************/ 314 | 315 | static const luaL_Reg object_table[] = { 316 | {"new", mod_lua_map_new}, // Only supported in C. 317 | {"create", mod_lua_map_new}, // Supported in all languages. 318 | {"iterator", mod_lua_map_pairs}, 319 | {"pairs", mod_lua_map_pairs}, 320 | {"keys", mod_lua_map_keys}, 321 | {"values", mod_lua_map_values}, 322 | {"remove", mod_lua_map_remove}, 323 | {"size", mod_lua_map_size}, 324 | {"nbytes", mod_lua_map_nbytes}, 325 | {"tostring", mod_lua_map_tostring}, 326 | {0, 0} 327 | }; 328 | 329 | static const luaL_Reg object_metatable[] = { 330 | {"__call", mod_lua_map_cons}, 331 | {0, 0} 332 | }; 333 | 334 | /****************************************************************************** 335 | * CLASS TABLE 336 | *****************************************************************************/ 337 | 338 | /* 339 | static const luaL_Reg class_table[] = { 340 | {0, 0} 341 | }; 342 | */ 343 | 344 | static const luaL_Reg class_metatable[] = { 345 | {"__index", mod_lua_map_index}, 346 | {"__newindex", mod_lua_map_newindex}, 347 | {"__len", mod_lua_map_len}, 348 | {"__tostring", mod_lua_map_tostring}, 349 | {"__gc", mod_lua_map_gc}, 350 | {0, 0} 351 | }; 352 | 353 | /****************************************************************************** 354 | * REGISTER 355 | *****************************************************************************/ 356 | 357 | int mod_lua_map_register(lua_State * l) { 358 | mod_lua_reg_object(l, OBJECT_NAME, object_table, object_metatable); 359 | mod_lua_reg_class(l, CLASS_NAME, NULL, class_metatable); 360 | return 1; 361 | } 362 | -------------------------------------------------------------------------------- /src/main/mod_lua_record.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2022 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "internal.h" 28 | 29 | /******************************************************************************* 30 | * MACROS 31 | ******************************************************************************/ 32 | 33 | #define OBJECT_NAME "record" 34 | #define CLASS_NAME "Record" 35 | 36 | /******************************************************************************* 37 | * FUNCTIONS 38 | ******************************************************************************/ 39 | 40 | /** 41 | * Read the item at index and convert to a record 42 | */ 43 | as_rec * mod_lua_torecord(lua_State * l, int index) { 44 | mod_lua_box * box = mod_lua_tobox(l, index, CLASS_NAME); 45 | return (as_rec *) mod_lua_box_value(box); 46 | } 47 | 48 | /** 49 | * Push a record on to the lua stack 50 | */ 51 | as_rec * mod_lua_pushrecord(lua_State * l, as_rec * r) { 52 | // I am hoping the following is correct use of the free flag 53 | mod_lua_box * box = mod_lua_pushbox(l, r->_.free ? MOD_LUA_SCOPE_LUA : MOD_LUA_SCOPE_HOST, r, CLASS_NAME); 54 | return (as_rec *) mod_lua_box_value(box); 55 | } 56 | 57 | /** 58 | * Get the user record from the stack at index 59 | */ 60 | static as_rec * mod_lua_checkrecord(lua_State * l, int index) { 61 | mod_lua_box * box = mod_lua_checkbox(l, index, CLASS_NAME); 62 | return (as_rec *) mod_lua_box_value(box); 63 | } 64 | 65 | /** 66 | * Garbage collection 67 | */ 68 | static int mod_lua_record_gc(lua_State * l) { 69 | mod_lua_freebox(l, 1, CLASS_NAME); 70 | return 0; 71 | } 72 | 73 | /** 74 | * Get a record ttl: 75 | * record.ttl(r) 76 | */ 77 | static int mod_lua_record_ttl(lua_State * l) { 78 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 79 | lua_pushinteger(l, as_rec_ttl(rec)); 80 | return 1; 81 | } 82 | 83 | /** 84 | * Get a record's last update time: 85 | * record.last_update_time(r) 86 | */ 87 | static int mod_lua_record_last_update_time(lua_State * l) { 88 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 89 | lua_pushinteger(l, as_rec_last_update_time(rec)); 90 | return 1; 91 | } 92 | 93 | /** 94 | * Get a record generation: 95 | * record.gen(r) 96 | */ 97 | static int mod_lua_record_gen(lua_State * l) { 98 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 99 | lua_pushinteger(l, as_rec_gen(rec)); 100 | return 1; 101 | } 102 | 103 | /** 104 | * Get a record's stored size (bytes): 105 | * record.size(r) 106 | */ 107 | static int mod_lua_record_size(lua_State * l) { 108 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 109 | lua_pushinteger(l, as_rec_size(rec)); 110 | return 1; 111 | } 112 | 113 | /** 114 | * Deprecated! 115 | * Get a record's memory storage size: 116 | * record.memory_size(r) 117 | */ 118 | static int mod_lua_record_memory_size(lua_State * l) { 119 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 120 | lua_pushinteger(l, as_rec_memory_size(rec)); 121 | return 1; 122 | } 123 | 124 | /** 125 | * Deprecated! 126 | * Get a record's device storage size: 127 | * record.device_size(r) 128 | */ 129 | static int mod_lua_record_device_size(lua_State * l) { 130 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 131 | lua_pushinteger(l, as_rec_device_size(rec)); 132 | return 1; 133 | } 134 | 135 | /** 136 | * Get a record key: 137 | * record.key(r) 138 | */ 139 | static int mod_lua_record_key(lua_State * l) { 140 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 141 | as_val * value = (as_val *) as_rec_key(rec); 142 | if ( value != NULL ) { 143 | mod_lua_pushval(l, value); 144 | as_val_destroy(value); 145 | return 1; 146 | } 147 | else { 148 | lua_pushnil(l); 149 | return 1; 150 | } 151 | } 152 | 153 | /** 154 | * Get a set name: 155 | * record.setname(r) 156 | */ 157 | static int mod_lua_record_setname(lua_State * l) { 158 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 159 | lua_pushstring(l, as_rec_setname(rec)); 160 | return 1; 161 | } 162 | 163 | /** 164 | * Get a record digest: 165 | * record.digest(r) 166 | */ 167 | static int mod_lua_record_digest(lua_State * l) { 168 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 169 | as_bytes * b = as_rec_digest(rec); 170 | mod_lua_pushbytes(l, b); 171 | return 1; 172 | } 173 | 174 | /** 175 | * Get a record numbins: 176 | * record.numbins(r) 177 | */ 178 | static int mod_lua_record_numbins(lua_State * l) { 179 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 180 | lua_pushinteger(l, as_rec_numbins(rec)); 181 | return 1; 182 | } 183 | 184 | typedef struct { 185 | lua_State * state; 186 | int return_val; 187 | } bin_names_data; 188 | 189 | void bin_names_callback(char * bin_names, uint32_t nbins, uint16_t max_name_size, void * udata) { 190 | bin_names_data * data = (bin_names_data *) udata; 191 | lua_State * l = data->state; 192 | lua_createtable(l, nbins, 0); 193 | 194 | for (uint32_t i = 0; i < nbins; i++) { 195 | lua_pushstring(l, &bin_names[i * max_name_size]); 196 | lua_rawseti(l, -2, i + 1); 197 | } 198 | } 199 | 200 | /** 201 | * Get a table of a record's bin names: 202 | * record.bin_names(r) 203 | */ 204 | static int mod_lua_record_bin_names(lua_State * l) { 205 | as_rec * rec = (as_rec *) mod_lua_checkrecord(l, 1); 206 | bin_names_data udata = {.state = l, .return_val = 0}; 207 | 208 | // Hook will either return non-0 (error) or make callback and return 0. 209 | if (as_rec_bin_names(rec, bin_names_callback, (void *)&udata) != 0) { 210 | return luaL_error(l, "can't get bin names"); 211 | } 212 | 213 | return 1; 214 | } 215 | 216 | /** 217 | * Set a record time to live (ttl) 218 | */ 219 | static int mod_lua_record_set_ttl(lua_State * l) { 220 | as_rec * rec = mod_lua_checkrecord(l, 1); 221 | 222 | // Get the 2nd arg off the stack -- and process as ttl 223 | uint32_t ttl = (uint32_t)luaL_optinteger(l, 2, 0); 224 | 225 | // This function just sets up the arguments, 226 | // The udf record method will do the real work. 227 | as_rec_set_ttl( rec, ttl ); 228 | 229 | return 0; 230 | } 231 | 232 | /** 233 | * Drop a record's key 234 | */ 235 | static int mod_lua_record_drop_key(lua_State * l) { 236 | as_rec * rec = mod_lua_checkrecord(l, 1); 237 | 238 | // This function just sets up the arguments, 239 | // The udf record method will do the real work. 240 | as_rec_drop_key( rec ); 241 | 242 | return 0; 243 | } 244 | 245 | /** 246 | * Get a value from the named bin 247 | */ 248 | static int mod_lua_record_index(lua_State * l) { 249 | mod_lua_box * box = mod_lua_checkbox(l, 1, CLASS_NAME); 250 | as_rec * rec = (as_rec *) mod_lua_box_value(box); 251 | const char * name = luaL_optstring(l, 2, 0); 252 | if ( name != NULL ) { 253 | as_val * value = (as_val *) as_rec_get(rec, name); 254 | if ( value != NULL ) { 255 | mod_lua_pushval(l, value); 256 | return 1; 257 | } 258 | else { 259 | lua_pushnil(l); 260 | return 1; 261 | } 262 | } 263 | else { 264 | lua_pushnil(l); 265 | return 1; 266 | } 267 | } 268 | 269 | 270 | /** 271 | * Set a value in the named bin 272 | */ 273 | static int mod_lua_record_newindex(lua_State * l) { 274 | as_rec * rec = mod_lua_checkrecord(l, 1); 275 | const char * name = luaL_optstring(l, 2, 0); 276 | if ( name != NULL ) { 277 | // reference to this value is created by mod_lua_toval 278 | // then stashed in the record cache 279 | as_val * value = (as_val *) mod_lua_toval(l, 3); 280 | if ( value == NULL ) { 281 | return luaL_error(l, "can't set bin %s to unsupported type", name); 282 | } 283 | 284 | as_rec_set(rec, name, value); 285 | } 286 | return 0; 287 | } 288 | 289 | /****************************************************************************** 290 | * OBJECT TABLE 291 | *****************************************************************************/ 292 | 293 | static const luaL_Reg object_table[] = { 294 | {"ttl", mod_lua_record_ttl}, 295 | {"last_update_time", mod_lua_record_last_update_time}, 296 | {"gen", mod_lua_record_gen}, 297 | {"size", mod_lua_record_size}, 298 | {"memory_size", mod_lua_record_memory_size}, 299 | {"device_size", mod_lua_record_device_size}, 300 | {"key", mod_lua_record_key}, 301 | {"setname", mod_lua_record_setname}, 302 | {"digest", mod_lua_record_digest}, 303 | {"numbins", mod_lua_record_numbins}, 304 | {"set_ttl", mod_lua_record_set_ttl}, 305 | {"drop_key", mod_lua_record_drop_key}, 306 | {"bin_names", mod_lua_record_bin_names}, 307 | {0, 0} 308 | }; 309 | 310 | static const luaL_Reg object_metatable[] = { 311 | // {"__index", mod_lua_record_index}, 312 | {0, 0} 313 | }; 314 | 315 | /****************************************************************************** 316 | * CLASS TABLE 317 | *****************************************************************************/ 318 | /* 319 | static const luaL_Reg class_table[] = { 320 | {0, 0} 321 | }; 322 | */ 323 | 324 | static const luaL_Reg class_metatable[] = { 325 | {"__index", mod_lua_record_index}, 326 | {"__newindex", mod_lua_record_newindex}, 327 | {"__gc", mod_lua_record_gc}, 328 | {0, 0} 329 | }; 330 | 331 | /******************************************************************************* 332 | * ~~~ Register ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 333 | ******************************************************************************/ 334 | 335 | int mod_lua_record_register(lua_State * l) { 336 | mod_lua_reg_object(l, OBJECT_NAME, object_table, object_metatable); 337 | mod_lua_reg_class(l, CLASS_NAME, NULL, class_metatable); 338 | return 1; 339 | } 340 | -------------------------------------------------------------------------------- /src/main/mod_lua_reg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2023 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include "internal.h" 24 | 25 | int 26 | mod_lua_reg_object(lua_State* l, const char* name, const luaL_Reg* table, 27 | const luaL_Reg* metatable) 28 | { 29 | lua_newtable(l); // -0 +1 30 | luaL_setfuncs(l, table, 0); // -0 +0 31 | lua_pushvalue(l, -1); // -0 +1 32 | lua_setglobal(l, name); // -1 +0 33 | 34 | int table_id = lua_gettop(l); // -0 +0 35 | 36 | lua_newtable(l); // -0 +1 37 | luaL_setfuncs(l, metatable, 0); // -0 +0 38 | 39 | int metatable_id = lua_gettop(l); // -0 +0 40 | 41 | lua_pushvalue(l, metatable_id); // -0 +1 42 | lua_setmetatable(l, table_id); // -1 +0 43 | 44 | lua_pushliteral(l, "__metatable"); // -0 +1 45 | lua_pushvalue(l, table_id); // -0 +1 46 | lua_rawset(l, metatable_id); // -2 +0 47 | 48 | lua_pop(l, 2); // -2 +0 - pop metatable and table 49 | 50 | return 0; 51 | } 52 | 53 | int 54 | mod_lua_reg_class(lua_State* l, const char* name, const luaL_Reg* table, 55 | const luaL_Reg* metatable) 56 | { 57 | int table_id = 0; 58 | int pop_cnt = 0; 59 | 60 | if (table != NULL) { 61 | lua_newtable(l); // -0 +1 62 | luaL_setfuncs(l, table, 0); // -0 +0 63 | lua_pushvalue(l, -1); // -0 +1 64 | lua_setglobal(l, name); // -1 +0 65 | table_id = lua_gettop(l); // -0 +0 66 | pop_cnt++; 67 | } 68 | 69 | int metatable_id = 0; 70 | 71 | if (metatable != NULL) { 72 | luaL_newmetatable(l, name); // -0 +1 73 | luaL_setfuncs(l, metatable, 0); // -0 +0 74 | metatable_id = lua_gettop(l); // -0 +0 75 | pop_cnt++; 76 | } 77 | 78 | if (table != NULL && metatable != NULL) { 79 | lua_pushliteral(l, "__index"); // -0 +1 80 | lua_pushvalue(l, table_id); // -0 +1 81 | lua_rawset(l, metatable_id); // -2 +0 82 | 83 | lua_pushliteral(l, "__metatable"); // -0 +1 84 | lua_pushvalue(l, table_id); // -0 +1 85 | lua_rawset(l, metatable_id); // -2 +0 86 | } 87 | 88 | lua_pop(l, pop_cnt); // -pop_cnt +0 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /src/main/mod_lua_stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "internal.h" 29 | 30 | 31 | /******************************************************************************* 32 | * MACROS 33 | ******************************************************************************/ 34 | 35 | #define OBJECT_NAME "stream" 36 | #define CLASS_NAME "Stream" 37 | 38 | /******************************************************************************* 39 | * FUNCTIONS 40 | ******************************************************************************/ 41 | 42 | as_stream * mod_lua_tostream(lua_State * l, int index) { 43 | mod_lua_box * box = mod_lua_tobox(l, index, CLASS_NAME); 44 | return (as_stream *) mod_lua_box_value(box); 45 | } 46 | 47 | as_stream * mod_lua_pushstream(lua_State * l, as_stream * stream) { 48 | mod_lua_box * box = mod_lua_pushbox(l, MOD_LUA_SCOPE_HOST, stream, CLASS_NAME); 49 | return (as_stream *) mod_lua_box_value(box); 50 | } 51 | 52 | // static as_stream * mod_lua_checkstream(lua_State * l, int index) { 53 | // mod_lua_box * box = mod_lua_checkbox(l, index, CLASS_NAME); 54 | // return (as_stream *) mod_lua_box_value(box); 55 | // } 56 | 57 | static int mod_lua_stream_gc(lua_State * l) { 58 | mod_lua_freebox(l, 1, CLASS_NAME); 59 | return 0; 60 | } 61 | 62 | static int mod_lua_stream_tostring(lua_State * l) { 63 | as_stream * stream = mod_lua_tostream(l, 1); 64 | char str[128] = { '\0' }; 65 | snprintf(str, 128, "Stream<%p>", stream); 66 | lua_pushstring(l, str); 67 | return 1; 68 | } 69 | 70 | static int mod_lua_stream_read(lua_State * l) { 71 | as_stream * stream = mod_lua_tostream(l, 1); 72 | if ( stream ) { 73 | as_val * val = as_stream_read(stream); 74 | mod_lua_pushval(l, val ); 75 | 76 | // Client aggregation queries read data from server nodes and populate this stream. After that, 77 | // the client has no use for this value. Therefore, destroy value after reading from this stream. 78 | // Enable on client build only. 79 | #ifdef AS_MOD_LUA_CLIENT 80 | as_val_destroy(val); 81 | #endif 82 | 83 | return 1; 84 | } 85 | else { 86 | lua_pushnil(l); 87 | return 1; 88 | } 89 | } 90 | 91 | static int mod_lua_stream_readable(lua_State * l) { 92 | as_stream * stream = mod_lua_tostream(l, 1); 93 | if ( stream ) { 94 | lua_pushboolean(l, as_stream_readable(stream)); 95 | return 1; 96 | } 97 | else { 98 | lua_pushboolean(l, false); 99 | return 1; 100 | } 101 | } 102 | 103 | static int mod_lua_stream_write(lua_State * l) { 104 | as_stream * stream = mod_lua_tostream(l, 1); 105 | if ( stream ) { 106 | as_val * val = mod_lua_toval(l, 2); 107 | if ( val == &as_nil ) { 108 | // as_nil terminates the stream in Lua, 109 | // while NULL terminates the stream in C, 110 | // so we map the former to the latter here. 111 | val = NULL; 112 | } 113 | int rc = as_stream_write(stream, val); 114 | lua_pushinteger(l, rc); 115 | return 1; 116 | } 117 | else { 118 | lua_pushinteger(l, AS_STREAM_ERR); 119 | return 1; 120 | } 121 | } 122 | 123 | static int mod_lua_stream_writable(lua_State * l) { 124 | as_stream * stream = mod_lua_tostream(l, 1); 125 | if ( stream ) { 126 | lua_pushboolean(l, as_stream_readable(stream)); 127 | return 1; 128 | } 129 | else { 130 | lua_pushboolean(l, false); 131 | return 1; 132 | } 133 | } 134 | 135 | /******************************************************************************* 136 | * OBJECT TABLE 137 | ******************************************************************************/ 138 | 139 | static const luaL_Reg object_table[] = { 140 | {"read", mod_lua_stream_read}, 141 | {"write", mod_lua_stream_write}, 142 | {"readable", mod_lua_stream_readable}, 143 | {"writable", mod_lua_stream_writable}, 144 | {"tostring", mod_lua_stream_tostring}, 145 | {0, 0} 146 | }; 147 | 148 | static const luaL_Reg object_metatable[] = { 149 | {0, 0} 150 | }; 151 | 152 | /******************************************************************************* 153 | * CLASS TABLE 154 | ******************************************************************************/ 155 | 156 | /* 157 | static const luaL_Reg class_table[] = { 158 | {0, 0} 159 | }; 160 | */ 161 | 162 | static const luaL_Reg class_metatable[] = { 163 | {"__tostring", mod_lua_stream_tostring}, 164 | {"__gc", mod_lua_stream_gc}, 165 | {0, 0} 166 | }; 167 | 168 | /******************************************************************************* 169 | * REGISTER 170 | ******************************************************************************/ 171 | 172 | int mod_lua_stream_register(lua_State * l) { 173 | mod_lua_reg_object(l, OBJECT_NAME, object_table, object_metatable); 174 | mod_lua_reg_class(l, CLASS_NAME, NULL, class_metatable); 175 | return 1; 176 | } 177 | -------------------------------------------------------------------------------- /src/main/mod_lua_system.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mod_lua_system.c 3 | * 4 | * Copyright (C) 2018-2023 Aerospike, Inc. 5 | * 6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 7 | * license agreements. 8 | * 9 | * This program is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Affero General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU Affero General Public License 20 | * along with this program. If not, see http://www.gnu.org/licenses/ 21 | */ 22 | 23 | #include 24 | 25 | // Auto-generated from system lua code in the lua-core repo. 26 | 27 | const char as_lua_as[] = 28 | "Map = Map or getmetatable(map())\n" 29 | "List = List or getmetatable(list())\n" 30 | "Bytes = Bytes or getmetatable(bytes())\n" 31 | "function list.clone(l)\n" 32 | " local ll = {}\n" 33 | " for v in list.iterator(l) do\n" 34 | " table.insert(ll, v)\n" 35 | " end\n" 36 | " return list(ll)\n" 37 | "end\n" 38 | "function list.merge(l1, l2)\n" 39 | " local ll = {}\n" 40 | " for v in list.iterator(l1) do\n" 41 | " table.insert(ll,v)\n" 42 | " end\n" 43 | " for v in list.iterator(l2) do\n" 44 | " table.insert(ll, v)\n" 45 | " end\n" 46 | " return list(ll)\n" 47 | "end\n" 48 | "function map.merge(m1,m2,f)\n" 49 | " local mm = {}\n" 50 | " for k,v in map.pairs(m1) do\n" 51 | " mm[k] = v\n" 52 | " end\n" 53 | " for k,v in map.pairs(m2) do\n" 54 | " mm[k] = (mm[k] and f and type(f) == 'function' and f(m1[k],m2[k])) or v\n" 55 | " end\n" 56 | " return map(mm, map.size(m1) + map.size(m2))\n" 57 | "end\n" 58 | "function map.diff(m1,m2)\n" 59 | " local mm = {}\n" 60 | " for k,v in map.pairs(m1) do\n" 61 | " if not m2[k] then\n" 62 | " mm[k] = v\n" 63 | " end\n" 64 | " end\n" 65 | " for k,v in map.pairs(m2) do\n" 66 | " if not m1[k] then\n" 67 | " mm[k] = v\n" 68 | " end\n" 69 | " end\n" 70 | " return map(mm, map.size(m1) + map.size(m2))\n" 71 | "end\n" 72 | "function map.clone(m)\n" 73 | " local mm = {}\n" 74 | " for k,v in map.pairs(m) do\n" 75 | " mm[k] = v\n" 76 | " end\n" 77 | " return map(mm, map.size(m))\n" 78 | "end\n" 79 | "function math.sum(a,b) \n" 80 | " return a + b\n" 81 | "end\n" 82 | "function math.product(a, b)\n" 83 | " return a * b\n" 84 | "end\n" 85 | ; 86 | 87 | size_t as_lua_as_size = sizeof(as_lua_as); 88 | 89 | const char as_lua_stream_ops[] = 90 | "local function check_limit(v)\n" 91 | " return type(v) == 'number' and v >= 1000\n" 92 | "end\n" 93 | "local function clone_table(t)\n" 94 | " local out = {}\n" 95 | " for k,v in pairs(t) do\n" 96 | " out[k] = v\n" 97 | " end\n" 98 | " return out\n" 99 | "end\n" 100 | "local function clone(v)\n" 101 | " local t = type(v)\n" 102 | " if t == 'number' then\n" 103 | " return v\n" 104 | " elseif t == 'string' then\n" 105 | " return v\n" 106 | " elseif t == 'boolean' then\n" 107 | " return v\n" 108 | " elseif t == 'table' then\n" 109 | " return clone_table(v)\n" 110 | " elseif t == 'userdata' then\n" 111 | " if getmetatable(v) == Map then\n" 112 | " return map.clone(v)\n" 113 | " elseif getmetatable(v) == List then\n" 114 | " return list.clone(v)\n" 115 | " end\n" 116 | " return nil\n" 117 | " end\n" 118 | " return v\n" 119 | "end\n" 120 | "function filter( next, p )\n" 121 | " local done = false\n" 122 | " return function()\n" 123 | " if done then return nil end\n" 124 | " for a in next do\n" 125 | " if p(a) then\n" 126 | " return a\n" 127 | " end\n" 128 | " end\n" 129 | " done = true\n" 130 | " return nil\n" 131 | " end\n" 132 | "end\n" 133 | "function transform( next, f )\n" 134 | " local done = false\n" 135 | " return function()\n" 136 | " if done then return nil end\n" 137 | " local a = next()\n" 138 | " if a ~= nil then\n" 139 | " return f(a)\n" 140 | " end\n" 141 | " done = true;\n" 142 | " return nil\n" 143 | " end\n" 144 | "end\n" 145 | "function reduce( next, f )\n" 146 | " local done = false\n" 147 | " return function()\n" 148 | " if done then return nil end\n" 149 | " local a = next()\n" 150 | " if a ~= nil then\n" 151 | " for b in next do\n" 152 | " a = f(a,b)\n" 153 | " end\n" 154 | " end\n" 155 | " done = true\n" 156 | " return a\n" 157 | " end\n" 158 | "end\n" 159 | "function aggregate( next, init, f )\n" 160 | " local done = false\n" 161 | " return function()\n" 162 | " if done then return nil end\n" 163 | " local a = clone(init)\n" 164 | " for b in next do\n" 165 | " a = f(a,b)\n" 166 | " if check_limit(a) then\n" 167 | " return a\n" 168 | " end\n" 169 | " end\n" 170 | " done = true\n" 171 | " return a\n" 172 | " end\n" 173 | "end\n" 174 | "function stream_iterator(s)\n" 175 | " local done = false\n" 176 | " return function()\n" 177 | " if done then return nil end\n" 178 | " local v = stream.read(s)\n" 179 | " if v == nil then\n" 180 | " done = true\n" 181 | " end\n" 182 | " return v;\n" 183 | " end\n" 184 | "end\n" 185 | "StreamOps = {}\n" 186 | "StreamOps_mt = { __index = StreamOps }\n" 187 | "local SCOPE_SERVER = 1\n" 188 | "local SCOPE_CLIENT = 2\n" 189 | "local SCOPE_EITHER = 3\n" 190 | "local SCOPE_BOTH = 4\n" 191 | "function StreamOps_create()\n" 192 | " local self = {}\n" 193 | " setmetatable(self, StreamOps_mt)\n" 194 | " self.ops = {}\n" 195 | " return self\n" 196 | "end\n" 197 | "function StreamOps_apply(stream, ops, i, n)\n" 198 | " i = i or 1\n" 199 | " n = n or #ops\n" 200 | " if i > n then return stream end\n" 201 | " local op = ops[i]\n" 202 | " local s = op.func(stream, table.unpack(op.args)) or stream\n" 203 | " return StreamOps_apply(s, ops, i + 1, n)\n" 204 | "end\n" 205 | "function StreamOps_select(stream_ops, scope)\n" 206 | " local server_ops = {}\n" 207 | " local client_ops = {}\n" 208 | " local phase = SCOPE_SERVER\n" 209 | " for i,op in ipairs(stream_ops) do\n" 210 | " if phase == SCOPE_SERVER then\n" 211 | " if op.scope == SCOPE_SERVER then\n" 212 | " table.insert(server_ops, op)\n" 213 | " elseif op.scope == SCOPE_EITHER then\n" 214 | " table.insert(server_ops, op)\n" 215 | " elseif op.scope == SCOPE_BOTH then\n" 216 | " table.insert(server_ops, op)\n" 217 | " table.insert(client_ops, op)\n" 218 | " phase = SCOPE_CLIENT\n" 219 | " end\n" 220 | " elseif phase == SCOPE_CLIENT then\n" 221 | " table.insert(client_ops, op)\n" 222 | " end\n" 223 | " end\n" 224 | " if scope == SCOPE_CLIENT then\n" 225 | " return client_ops\n" 226 | " else\n" 227 | " return server_ops\n" 228 | " end\n" 229 | "end\n" 230 | "function StreamOps:aggregate(...)\n" 231 | " table.insert(self.ops, { scope = SCOPE_SERVER, name = \"aggregate\", func = aggregate, args = {...}})\n" 232 | " return self\n" 233 | "end\n" 234 | "function StreamOps:reduce(...)\n" 235 | " table.insert(self.ops, { scope = SCOPE_BOTH, name = \"reduce\", func = reduce, args = {...}})\n" 236 | " return self\n" 237 | "end\n" 238 | "function StreamOps:map(...)\n" 239 | " table.insert(self.ops, { scope = SCOPE_EITHER, name = \"map\", func = transform, args = {...}})\n" 240 | " return self\n" 241 | "end\n" 242 | "function StreamOps:filter(...)\n" 243 | " table.insert(self.ops, { scope = SCOPE_EITHER, name = \"filter\", func = filter, args = {...}})\n" 244 | " return self\n" 245 | "end\n" 246 | "function StreamOps:groupby(f)\n" 247 | " local function _aggregate(m, v)\n" 248 | " local k = f and f(v) or nil;\n" 249 | " local l = m[k] or list()\n" 250 | " list.append(l, v)\n" 251 | " m[k] = l;\n" 252 | " return m;\n" 253 | " end\n" 254 | " local function _merge(l1, l2)\n" 255 | " local l = list.clone(l1)\n" 256 | " for v in list.iterator(l2) do\n" 257 | " list.append(l, v)\n" 258 | " end\n" 259 | " return l\n" 260 | " end\n" 261 | " function _reduce(m1, m2)\n" 262 | " return map.merge(m1, m2, _merge)\n" 263 | " end\n" 264 | " return self : aggregate(map(), _aggregate) : reduce(_reduce)\n" 265 | "end\n" 266 | ; 267 | 268 | size_t as_lua_stream_ops_size = sizeof(as_lua_stream_ops); 269 | 270 | const char as_lua_aerospike[] = 271 | "function trace(m, ...)\n" 272 | " return aerospike:log(4, string.format(m, ...))\n" 273 | "end\n" 274 | "function debug(m, ...)\n" 275 | " return aerospike:log(3, string.format(m, ...))\n" 276 | "end\n" 277 | "function info(m, ...)\n" 278 | " return aerospike:log(2, string.format(m, ...))\n" 279 | "end\n" 280 | "function warn(m, ...)\n" 281 | " return aerospike:log(1, string.format(m, ...))\n" 282 | "end\n" 283 | "function apply_record(f, r, ...)\n" 284 | " if f == nil then\n" 285 | " error(\"function not found\", 2)\n" 286 | " end\n" 287 | " success, result = pcall(f, r, ...)\n" 288 | " if success then\n" 289 | " return result\n" 290 | " else\n" 291 | " error(result, 2)\n" 292 | " return nil\n" 293 | " end\n" 294 | "end\n" 295 | "function apply_stream(f, scope, istream, ostream, ...)\n" 296 | " if f == nil then\n" 297 | " error(\"function not found\", 2)\n" 298 | " return 2\n" 299 | " end\n" 300 | " local stream_ops = StreamOps_create();\n" 301 | " success, result = pcall(f, stream_ops, ...)\n" 302 | " if success then\n" 303 | " local ops = StreamOps_select(result.ops, scope);\n" 304 | " local values = StreamOps_apply(stream_iterator(istream), ops);\n" 305 | " for value in values do\n" 306 | " if stream.write(ostream, value) ~= 0 then\n" 307 | " break\n" 308 | " end\n" 309 | " end\n" 310 | " stream.write(ostream, nil)\n" 311 | " return 0\n" 312 | " else\n" 313 | " error(result, 2)\n" 314 | " return 2\n" 315 | " end\n" 316 | "end\n" 317 | ; 318 | 319 | size_t as_lua_aerospike_size = sizeof(as_lua_aerospike); 320 | -------------------------------------------------------------------------------- /src/main/mod_lua_val.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "internal.h" 33 | 34 | as_val * mod_lua_takeval(lua_State * l, int i) { 35 | return mod_lua_toval(l, i); 36 | } 37 | 38 | as_val * mod_lua_retval(lua_State * l) { 39 | return mod_lua_toval(l, -1); 40 | } 41 | 42 | /** 43 | * Reads a val from the Lua stack 44 | * the val returned includes a refcount that must be freed later 45 | * 46 | * @param l the lua_State to read the val from 47 | * @param i the position of the val on the stack 48 | * @returns the val if exists, otherwise NULL. 49 | */ 50 | as_val* mod_lua_toval(lua_State* l, int i) { 51 | switch (lua_type(l, i)) { 52 | case LUA_TNUMBER: 53 | return (lua_isinteger(l, i)) == 1 ? 54 | (as_val*)as_integer_new(lua_tointeger(l, i)) : 55 | (as_val*)as_double_new(lua_tonumber(l, i)); 56 | case LUA_TBOOLEAN: 57 | return (as_val*)as_boolean_new(lua_toboolean(l, i)); 58 | case LUA_TSTRING: 59 | return (as_val*)as_string_new(cf_strdup(lua_tostring(l, i)), true); 60 | case LUA_TUSERDATA : { 61 | mod_lua_box* box = (mod_lua_box*)lua_touserdata(l, i); 62 | if ( box && box->value ) { 63 | switch (as_val_type(box->value)) { 64 | case AS_BOOLEAN: 65 | case AS_INTEGER: 66 | case AS_DOUBLE: 67 | case AS_STRING: 68 | case AS_BYTES: 69 | case AS_LIST: 70 | case AS_MAP: 71 | case AS_REC: 72 | case AS_GEOJSON: 73 | switch (box->scope) { 74 | case MOD_LUA_SCOPE_LUA: 75 | as_val_reserve(box->value); 76 | return box->value; 77 | case MOD_LUA_SCOPE_HOST: 78 | return box->value; 79 | } 80 | default: 81 | return NULL; 82 | } 83 | } 84 | else { 85 | return (as_val*)NULL; 86 | } 87 | } 88 | case LUA_TNIL : 89 | return (as_val*)&as_nil; 90 | case LUA_TTABLE : 91 | case LUA_TFUNCTION : 92 | case LUA_TLIGHTUSERDATA : 93 | default: 94 | return (as_val*)NULL; 95 | } 96 | } 97 | 98 | 99 | /** 100 | * Pushes a val onto the Lua stack 101 | * 102 | * @param l the lua_State to push the val onto 103 | * @param v the val to push on to the stack 104 | * @returns number of values pushed 105 | */ 106 | int mod_lua_pushval(lua_State * l, const as_val * v) { 107 | if ( v == NULL ) { 108 | lua_pushnil(l); 109 | return 1; 110 | } 111 | 112 | switch( as_val_type(v) ) { 113 | case AS_BOOLEAN: { 114 | lua_pushboolean(l, as_boolean_tobool((as_boolean *) v) ); 115 | return 1; 116 | } 117 | case AS_INTEGER: { 118 | lua_pushinteger(l, as_integer_toint((as_integer *) v) ); 119 | return 1; 120 | } 121 | case AS_DOUBLE: { 122 | lua_pushnumber(l, as_double_get((as_double*)v)); 123 | return 1; 124 | } 125 | case AS_STRING: { 126 | lua_pushstring(l, as_string_tostring((as_string *) v) ); 127 | return 1; 128 | } 129 | case AS_BYTES: { 130 | as_val_reserve(v); 131 | mod_lua_pushbytes(l, (as_bytes *) v); 132 | return 1; 133 | } 134 | case AS_LIST: { 135 | as_val_reserve(v); 136 | mod_lua_pushlist(l, (as_list *) v); 137 | return 1; 138 | } 139 | case AS_MAP: { 140 | as_val_reserve(v); 141 | mod_lua_pushmap(l, (as_map *) v); 142 | return 1; 143 | } 144 | case AS_REC: { 145 | as_val_reserve(v); 146 | mod_lua_pushrecord(l, (as_rec *) v); 147 | return 1; 148 | } 149 | case AS_PAIR: { 150 | as_pair * p = (as_pair *) lua_newuserdata(l, sizeof(as_pair)); 151 | *p = *((as_pair *)v); 152 | return 1; 153 | } 154 | case AS_GEOJSON: { 155 | as_val_reserve(v); 156 | mod_lua_pushgeojson(l, (as_geojson *) v); 157 | return 1; 158 | } 159 | default: { 160 | lua_pushnil(l); 161 | return 1; 162 | } 163 | } 164 | return 0; 165 | } 166 | 167 | 168 | 169 | mod_lua_box * mod_lua_newbox(lua_State * l, mod_lua_scope scope, void * value, const char * type) { 170 | mod_lua_box * box = (mod_lua_box *) lua_newuserdata(l, sizeof(mod_lua_box)); 171 | box->scope = scope; 172 | box->value = value; 173 | return box; 174 | } 175 | 176 | mod_lua_box * mod_lua_pushbox(lua_State * l, mod_lua_scope scope, void * value, const char * type) { 177 | mod_lua_box * box = (mod_lua_box *) mod_lua_newbox(l, scope, value, type); 178 | luaL_getmetatable(l, type); 179 | lua_setmetatable(l, -2); 180 | return box; 181 | } 182 | 183 | mod_lua_box * mod_lua_tobox(lua_State * l, int index, const char * type) { 184 | mod_lua_box * box = (mod_lua_box *) lua_touserdata(l, index); 185 | if (box == NULL && type != NULL ) mod_lua_typerror(l, index, type); 186 | return box; 187 | } 188 | 189 | mod_lua_box * mod_lua_checkbox(lua_State * l, int index, const char * type) { 190 | luaL_checktype(l, index, LUA_TUSERDATA); 191 | mod_lua_box * box = (mod_lua_box *) luaL_checkudata(l, index, type); 192 | if (box == NULL) mod_lua_typerror(l, index, type); 193 | return box; 194 | } 195 | 196 | int mod_lua_freebox(lua_State * l, int index, const char * type) { 197 | mod_lua_box * box = mod_lua_checkbox(l, index, type); 198 | if ( box != NULL && box->scope == MOD_LUA_SCOPE_LUA && box->value != NULL ) { 199 | as_val_destroy(box->value); 200 | box->value = NULL; 201 | } 202 | return 0; 203 | } 204 | 205 | void * mod_lua_box_value(mod_lua_box * box) { 206 | return box ? box->value : NULL; 207 | } 208 | -------------------------------------------------------------------------------- /src/test/hash/hash_udf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "../test.h" 27 | #include "../util/map_rec.h" 28 | #include "../util/test_aerospike.h" 29 | #include "../util/test_logger.h" 30 | 31 | struct lua_hash_ele_s; 32 | typedef struct lua_hash_ele_s lua_hash_ele; 33 | 34 | struct lua_hash_s; 35 | typedef struct lua_hash_s lua_hash; 36 | struct cache_entry_s; 37 | typedef struct cache_entry_s cache_entry; 38 | 39 | void lua_hash_clear(lua_hash* h, void (*cb)(cache_entry *)); 40 | lua_hash* lua_hash_create(uint32_t n_rows); 41 | void lua_hash_destroy(lua_hash* h); 42 | bool lua_hash_get(const lua_hash* h, const char* key, cache_entry** p_value); 43 | cache_entry* lua_hash_put(lua_hash* h, const char* key, cache_entry* value); 44 | cache_entry* lua_hash_remove(lua_hash* h, const char* key); 45 | 46 | static const char* a_val = "test1"; 47 | static const char* b_val = "test2"; 48 | static const char* c_val = "test3"; 49 | static const char* d_val = "test4"; 50 | 51 | static const char* orig_val = "me"; 52 | static const char* replacement_val = "you"; 53 | 54 | static uint8_t val_count; 55 | static char vals[5][6]; 56 | 57 | lua_hash* h; 58 | /****************************************************************************** 59 | * TEST CASES 60 | *****************************************************************************/ 61 | static void 62 | hash_udf_setup_test() 63 | { 64 | h = lua_hash_create(3); 65 | lua_hash_put(h, "a", (cache_entry*)a_val); 66 | lua_hash_put(h, "b", (cache_entry*)b_val); 67 | lua_hash_put(h, "c", (cache_entry*)c_val); 68 | lua_hash_put(h, "d", (cache_entry*)d_val); 69 | debug("setting up"); 70 | val_count = 0; 71 | vals[0][0] = '\0'; 72 | vals[1][0] = '\0'; 73 | vals[2][0] = '\0'; 74 | vals[3][0] = '\0'; 75 | } 76 | 77 | static void 78 | hash_udf_teardown_test() 79 | { 80 | debug("tearing down"); 81 | 82 | // Not used by client or server, for this test only. 83 | lua_hash_destroy(h); 84 | } 85 | 86 | void 87 | clear_cb(cache_entry* centry) { 88 | char* entry_str = (char*)centry; 89 | strncpy((vals[val_count++]), (char*)entry_str, 5); 90 | } 91 | 92 | // asserts don't work from outside of test functions therefore this bit of "..." 93 | bool 94 | remove_ok(const char* key, const char* val) 95 | { 96 | char* from_hash; 97 | 98 | return lua_hash_get(h, key, (cache_entry**)&from_hash) && // key exists 99 | from_hash == val && // with an expected value 100 | lua_hash_remove(h, key) == (cache_entry*)val && // removing succeeded 101 | ! lua_hash_get(h, key, (cache_entry**)&from_hash) && // key ! exists 102 | lua_hash_remove(h, key) == NULL; // second remove fails 103 | } 104 | 105 | TEST(hash_udf_1, "gets succeed and return correct value if key exists") 106 | { 107 | 108 | hash_udf_setup_test(); 109 | 110 | char* from_hash; 111 | 112 | assert_true(lua_hash_get(h, "a", (cache_entry**)&from_hash)); 113 | assert_true(from_hash == a_val); 114 | assert_true(lua_hash_get(h, "b", (cache_entry**)&from_hash)); 115 | assert_true(from_hash == b_val); 116 | assert_true(lua_hash_get(h, "c", (cache_entry**)&from_hash)); 117 | assert_true(from_hash == c_val); 118 | assert_true(lua_hash_get(h, "d", (cache_entry**)&from_hash)); 119 | assert_true(from_hash == d_val); 120 | 121 | assert_true(lua_hash_get(h, "d", NULL)); 122 | assert_false(lua_hash_get(h, "FAKWAN", NULL)); 123 | assert_false(lua_hash_get(h, "FAKWAN", (cache_entry**)&from_hash)); 124 | 125 | hash_udf_teardown_test(); 126 | } 127 | 128 | TEST(hash_udf_2, "removes work correctly for all positions in hash") 129 | { 130 | hash_udf_setup_test(); 131 | 132 | assert_null(lua_hash_remove(h, "FAKWAN")); 133 | assert_true(remove_ok("c", c_val)); 134 | assert_true(remove_ok("a", a_val)); 135 | assert_true(remove_ok("b", b_val)); 136 | assert_true(remove_ok("d", d_val)); 137 | 138 | hash_udf_teardown_test(); 139 | } 140 | 141 | TEST(hash_udf_3, "clear removes all items in hash") 142 | { 143 | hash_udf_setup_test(); 144 | 145 | lua_hash_clear(h, NULL); 146 | assert_false(lua_hash_get(h, "a", NULL)); 147 | assert_false(lua_hash_get(h, "b", NULL)); 148 | assert_false(lua_hash_get(h, "c", NULL)); 149 | assert_false(lua_hash_get(h, "d", NULL)); 150 | lua_hash_clear(h, NULL); // should be able to call on empty hash without crash 151 | 152 | hash_udf_teardown_test(); 153 | } 154 | 155 | TEST(hash_udf_4, "cleared hash still usable") 156 | { 157 | char* from_hash; 158 | hash_udf_setup_test(); 159 | 160 | lua_hash_clear(h, NULL); 161 | lua_hash_put(h, "a", (cache_entry*)a_val); 162 | lua_hash_put(h, "b", (cache_entry*)b_val); 163 | lua_hash_put(h, "c", (cache_entry*)c_val); 164 | lua_hash_put(h, "d", (cache_entry*)d_val); 165 | assert_true(lua_hash_get(h, "a", (cache_entry**)&from_hash)); 166 | assert_true(from_hash == a_val); 167 | assert_true(lua_hash_get(h, "b", (cache_entry**)&from_hash)); 168 | assert_true(from_hash == b_val); 169 | assert_true(lua_hash_get(h, "c", (cache_entry**)&from_hash)); 170 | assert_true(from_hash == c_val); 171 | assert_true(lua_hash_get(h, "d", (cache_entry**)&from_hash)); 172 | assert_true(from_hash == d_val); 173 | 174 | hash_udf_teardown_test(); 175 | } 176 | 177 | TEST(hash_udf_5, "cleared hash callback is called correctly") 178 | { 179 | hash_udf_setup_test(); 180 | 181 | lua_hash_clear(h, &clear_cb); 182 | // These depend on the order in the hash. The hash is stable so we can 183 | // hardcode it. 184 | assert_string_eq(vals[0], "test3"); 185 | assert_string_eq(vals[1], "test1"); 186 | assert_string_eq(vals[2], "test2"); 187 | assert_string_eq(vals[3], "test4"); 188 | assert_int_eq(val_count, 4); 189 | 190 | hash_udf_teardown_test(); 191 | } 192 | 193 | TEST(hash_udf_6, "replacing a key works and returns previous value, long keys get truncated.") 194 | { 195 | hash_udf_setup_test(); 196 | 197 | char* from_hash; 198 | cache_entry* ret = lua_hash_put(h, "help", (cache_entry*)orig_val); 199 | assert_null(ret); 200 | assert_true(lua_hash_get(h, "help", (cache_entry**)&from_hash)); 201 | assert_true(from_hash == orig_val); 202 | ret = lua_hash_put(h, "help", (cache_entry*)replacement_val); 203 | assert_true(ret == (cache_entry*)orig_val); 204 | assert_true(lua_hash_get(h, "help", (cache_entry**)&from_hash)); 205 | assert_string_eq(from_hash, replacement_val); 206 | 207 | hash_udf_teardown_test(); 208 | } 209 | 210 | /****************************************************************************** 211 | * TEST SUITE 212 | *****************************************************************************/ 213 | SUITE(hash_udf, "list udf tests") 214 | { 215 | suite_before(test_suite_before); 216 | suite_after(test_suite_after); 217 | 218 | suite_add(hash_udf_1); 219 | suite_add(hash_udf_2); 220 | suite_add(hash_udf_3); 221 | suite_add(hash_udf_4); 222 | suite_add(hash_udf_5); 223 | suite_add(hash_udf_6); 224 | } 225 | -------------------------------------------------------------------------------- /src/test/lua/aggr.lua: -------------------------------------------------------------------------------- 1 | 2 | function even(s) 3 | 4 | local function _even(a) 5 | return a % 2 == 0 6 | end 7 | 8 | return s : filter(_even) 9 | end 10 | 11 | function increment(s) 12 | 13 | local function _map(a) 14 | return a + 1 15 | end 16 | 17 | return s : map(_map) 18 | end 19 | 20 | local function add(a,b) 21 | return a + b; 22 | end 23 | 24 | local function select(bin) 25 | return function (rec) 26 | return rec[bin] 27 | end 28 | end 29 | 30 | function sum(s) 31 | return s : reduce(add) 32 | end 33 | 34 | function product(s) 35 | return s : reduce(math.product) 36 | end 37 | 38 | function rollup(s) 39 | 40 | local function _map(a) 41 | return map{ [a.campaign] = a.views } 42 | end 43 | 44 | local function _reduce(a, b) 45 | return map.merge(a, b, math.sum) 46 | end 47 | 48 | 49 | return s : map(_map) : reduce(_reduce) 50 | end 51 | 52 | function rollup2(s) 53 | 54 | local function _aggregate(a,b) 55 | a[b.campaign] = (a[b.campaign] or 0) + b.views 56 | return a 57 | end 58 | 59 | return s : aggregate(map(), _aggregate) 60 | end -------------------------------------------------------------------------------- /src/test/lua/basics.lua: -------------------------------------------------------------------------------- 1 | 2 | function getboolean(record) 3 | return true 4 | end 5 | 6 | function getfloat(record) 7 | return 123.987 8 | end 9 | 10 | function getinteger(record) 11 | return 123 12 | end 13 | 14 | function getstring(record) 15 | return "abc" 16 | end 17 | 18 | function gettable(record) 19 | return {1,2,3} 20 | end 21 | 22 | function getlist(record) 23 | return list {1,2,3} 24 | end 25 | 26 | function getmap(record) 27 | return map {["a"] = 1, ["b"] = 2, ["c"] = 3} 28 | end 29 | 30 | function concat(record, a, b) 31 | return a .. b 32 | end 33 | 34 | function add(record, a, b) 35 | return a + b 36 | end 37 | 38 | function sum(record, a, b) 39 | return add(record, a, b) 40 | end 41 | 42 | local function difference(record, a, b) 43 | return a - b 44 | end 45 | 46 | function diff(record, a, b) 47 | return difference(record, a, b) 48 | end 49 | -------------------------------------------------------------------------------- /src/test/lua/bytes.lua: -------------------------------------------------------------------------------- 1 | 2 | function set(r,b,l) 3 | r[b] = l 4 | if aerospike:exists(r) then 5 | aerospike:create(r) 6 | else 7 | aerospike:update(r) 8 | end 9 | 10 | if aerospike:exists(r) then 11 | info("record exists!") 12 | else 13 | info("record doesn't exist!") 14 | end 15 | return 0 16 | end 17 | 18 | function get(r,b) 19 | local l = r[b] 20 | if l == nil then 21 | return 1 22 | else 23 | return 0 24 | end 25 | end 26 | 27 | function newbytes(r,a,b,c) 28 | local b = bytes{1,2,3} 29 | info("1 => %s",b[1] or "") 30 | info("2 => %s",b[2] or "") 31 | info("3 => %s",b[3] or "") 32 | return l[2] 33 | end 34 | -------------------------------------------------------------------------------- /src/test/lua/errors.lua: -------------------------------------------------------------------------------- 1 | 2 | function syntax_error(r) 3 | { 4 | , 5 | } 6 | end 7 | -------------------------------------------------------------------------------- /src/test/lua/integers.lua: -------------------------------------------------------------------------------- 1 | 2 | function add(r,...) 3 | local out = select(1,...) 4 | local len = select('#',...) 5 | for i=2, len do 6 | out = out + select(i,...) 7 | end 8 | return out 9 | end 10 | 11 | function sub(r,...) 12 | local out = select(1,...) 13 | local len = select('#',...) 14 | for i=2, len do 15 | out = out - select(i,...) 16 | end 17 | return out 18 | end 19 | 20 | function mult(r,...) 21 | local out = select(1,...) 22 | local len = select('#',...) 23 | for i=2, len do 24 | out = out * select(i,...) 25 | end 26 | return out 27 | end 28 | 29 | function div(r,...) 30 | local out = select(1,...) 31 | local len = select('#',...) 32 | for i=2, len do 33 | out = out / select(i,...) 34 | end 35 | return out 36 | end 37 | 38 | function pow(r,...) 39 | local out = select(1,...) 40 | local len = select('#',...) 41 | for i=2, len do 42 | out = out ^ select(i,...) 43 | end 44 | return out 45 | end 46 | 47 | function mod(r,...) 48 | local out = select(1,...) 49 | local len = select('#',...) 50 | for i=2, len do 51 | out = out % select(i,...) 52 | end 53 | return out 54 | end 55 | 56 | function echo(r,a) 57 | return a 58 | end -------------------------------------------------------------------------------- /src/test/lua/lists.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Functions to support tests of list operations. 3 | -- 4 | 5 | function create(rec,...) 6 | -- Return a list of the args. 7 | local len = select('#',...) 8 | local l = list.create(len) 9 | if l == nil then 10 | warn("list creation failed") 11 | else 12 | for i = 1, len do 13 | l[i] = select(i,...) 14 | end 15 | end 16 | return l 17 | end 18 | 19 | function size(rec, bname) 20 | local l = rec[bname] 21 | if l == nil then 22 | warn("nothing found in bin %s", bname) 23 | end 24 | return list.size(l) 25 | end 26 | 27 | function iterate(rec, bname) 28 | local l = rec[bname] 29 | if l == nil then 30 | warn("nothing found in bin %s", bname) 31 | end 32 | -- Create a list that looks just like the input one. 33 | local l2 = list.create(list.size(l)) 34 | local i = 1 35 | for v in list.iterator(l) do 36 | l2[i] = v 37 | i = i + 1 38 | end 39 | return l2 40 | end 41 | 42 | function insert(rec, bname, pos, val) 43 | local l = rec[bname] 44 | if l == nil then 45 | warn("nothing found in bin %s", bname) 46 | end 47 | list.insert(l, pos, val) 48 | return l 49 | end 50 | 51 | function append(rec, bname, val) 52 | local l = rec[bname] 53 | if l == nil then 54 | warn("nothing found in bin %s", bname) 55 | end 56 | list.append(l, val) 57 | return l 58 | end 59 | 60 | function prepend(rec, bname, val) 61 | local l = rec[bname] 62 | if l == nil then 63 | warn("nothing found in bin %s", bname) 64 | end 65 | list.prepend(l, val) 66 | return l 67 | end 68 | 69 | function take(rec, bname, n) 70 | local l = rec[bname] 71 | if l == nil then 72 | warn("nothing found in bin %s", bname) 73 | end 74 | return list.take(l, n) 75 | end 76 | 77 | function remove(rec, bname, pos) 78 | local l = rec[bname] 79 | if l == nil then 80 | warn("nothing found in bin %s", bname) 81 | end 82 | list.remove(l, pos) 83 | return l 84 | end 85 | 86 | function drop(rec, bname, n) 87 | local l = rec[bname] 88 | if l == nil then 89 | warn("nothing found in bin %s", bname) 90 | end 91 | return list.drop(l, n) 92 | end 93 | 94 | function trim(rec, bname, pos) 95 | local l = rec[bname] 96 | if l == nil then 97 | warn("nothing found in bin %s", bname) 98 | end 99 | list.trim(l, pos) 100 | return l 101 | end 102 | 103 | function clone(rec, bname) 104 | local l = rec[bname] 105 | if l == nil then 106 | warn("nothing found in bin %s", bname) 107 | end 108 | return list.clone(l) 109 | end 110 | 111 | function concat(rec, bname, bname2) 112 | local l = rec[bname] 113 | if l == nil then 114 | warn("nothing found in bin %s", bname) 115 | end 116 | local l2 = rec[bname2] 117 | if l2 == nil then 118 | warn("nothing found in bin %s", bname2) 119 | end 120 | list.concat(l, l2) 121 | return l 122 | end 123 | 124 | function merge(rec, bname, bname2) 125 | local l = rec[bname] 126 | if l == nil then 127 | warn("nothing found in bin %s", bname) 128 | end 129 | local l2 = rec[bname2] 130 | if l2 == nil then 131 | warn("nothing found in bin %s", bname2) 132 | end 133 | return list.merge(l, l2) 134 | end 135 | 136 | -------------------------------------------------------------------------------- /src/test/lua/logs.lua: -------------------------------------------------------------------------------- 1 | 2 | function INFO(r,m) 3 | info(m) 4 | return 1 5 | end 6 | 7 | function WARN(r,m) 8 | warn(m) 9 | return 1 10 | end 11 | 12 | function DEBUG(r,m) 13 | debug(m) 14 | return 1 15 | end 16 | 17 | function TRACE(r,m) 18 | trace(m) 19 | return 1 20 | end -------------------------------------------------------------------------------- /src/test/lua/maps.lua: -------------------------------------------------------------------------------- 1 | function new(r,bin,...) 2 | local m = map() 3 | local len = select('#',...) 4 | 5 | if len % 2 > 0 then error("odd number of elements") end 6 | 7 | for i=1, len do 8 | if i % 2 == 1 then 9 | local k = select(i,...) 10 | local v = select(i+1,...) 11 | m[k] = v 12 | end 13 | end 14 | 15 | r[bin] = m 16 | 17 | return r[bin] 18 | end 19 | 20 | function set(r,k,v) 21 | local m = map() 22 | m[k] = v 23 | return m[k] 24 | end 25 | 26 | function get(r,bin,key) 27 | local m = r[bin] 28 | return m[key] 29 | end 30 | 31 | function newmap(r,bin,a,b,c) 32 | local m = map {a=a,b=b,c=c} 33 | info("%s => %s", "a", m.a or "") 34 | info("%s => %s", "b", m.b or "") 35 | info("%s => %s", "b", m.c or "") 36 | return m["b"] 37 | end 38 | 39 | function putmap(r,bin,m) 40 | r[bin] = m 41 | info("%s => %s", "A", m['A'] or "") 42 | info("%s => %s", "B", m['B'] or "") 43 | info("%s => %s", "C", m['C'] or "") 44 | aerospike:create(r); 45 | return r[bin] 46 | end 47 | 48 | function getmap(r,bin) 49 | info("%s => %s", "A", r[bin]['A'] or "") 50 | return r[bin] 51 | end 52 | 53 | 54 | function mapput(r, map, k, v) 55 | map[k] = v 56 | return map 57 | end 58 | 59 | function show(r, map, k) 60 | info("show: %s",map[k]); 61 | return map; 62 | end 63 | -------------------------------------------------------------------------------- /src/test/lua/raj.lua: -------------------------------------------------------------------------------- 1 | 2 | local function add(a, b) 3 | return a + b; 4 | end 5 | 6 | function sum_on_match(s, bin, val) 7 | 8 | local function _map(rec) 9 | if rec[bin] == val then 10 | return val; 11 | else 12 | return 0; 13 | end 14 | end 15 | 16 | return s : map(_map) : reduce(add); 17 | end 18 | -------------------------------------------------------------------------------- /src/test/lua/records.lua: -------------------------------------------------------------------------------- 1 | 2 | local function _join(r,delim,...) 3 | local out = '' 4 | local len = select('#',...) 5 | for i=1, len do 6 | if i > 1 then 7 | out = out .. (delim or ',') 8 | end 9 | out = out .. r[select(i,...)] 10 | end 11 | return out 12 | end 13 | 14 | function join(r,delim,...) 15 | return _join(r,delim,...) 16 | end 17 | 18 | function cat(r,...) 19 | return _join(r,'',...) 20 | end 21 | 22 | -- Generic example 23 | function example_lua(r,arg1,arg2,arg3,arg4) 24 | r[arg1] = arg2; 25 | r[arg3] = arg4; 26 | aerospike:update(r); 27 | return r['b']; 28 | end 29 | 30 | -- Get a particular bin 31 | function getbin(r,name) 32 | return r[name] 33 | end 34 | 35 | -- Set a particular bin 36 | function setbin(r,name,value) 37 | if not aerospike:exists(r) then aerospike:create(r) end 38 | local old = r[name] 39 | r[name] = value 40 | aerospike:update(r) 41 | return old 42 | end 43 | 44 | -- Set a particular bin 45 | function setbin2(r,name,value) 46 | local old = r[name] 47 | r[name] = value 48 | if not aerospike:exists(r) then 49 | aerospike:create(r) 50 | else 51 | aerospike:create(r) 52 | end 53 | return old 54 | end 55 | 56 | -- Set a particular bin 57 | function set_and_get(r,name,value) 58 | r[name] = value 59 | aerospike:update(r) 60 | return r[name] 61 | end 62 | 63 | -- Remove a paritcular bin 64 | function remove(r,name) 65 | local old = r[name] 66 | r[name] = nil 67 | aerospike:update(r) 68 | return old 69 | end 70 | 71 | -- Create a record 72 | function create_record(r,b1,v1,b2,v2) 73 | if not aerospike:exists(r) then 74 | aerospike:create(r); 75 | info("created"); 76 | else 77 | info("not created record already exists"); 78 | end 79 | if b1 and v1 then 80 | r[b1] = v1 81 | if b2 and v2 then 82 | r[b2] = v2 83 | end 84 | aerospike:update(r); 85 | info("updated!") 86 | end 87 | return r[b1] 88 | end 89 | 90 | -- delete a record 91 | function delete_record(r,name) 92 | info ("here"); 93 | if aerospike:exist(r) then 94 | info("exist. delete now"); 95 | return aerospike.remove(r) 96 | else 97 | info("not exist, delete should do nothing"); 98 | return aerospike.remove(r) 99 | end 100 | end 101 | 102 | -- @TODO return record as is 103 | -- function echo_record(record) 104 | -- return record; 105 | -- end 106 | 107 | 108 | -------------------------------------------------------------------------------- /src/test/lua/strings.lua: -------------------------------------------------------------------------------- 1 | local function _join(r,delim,...) 2 | local out = '' 3 | local len = select('#',...) 4 | for i=1, len do 5 | if i > 1 then 6 | out = out .. (delim or ',') 7 | end 8 | out = out .. select(i,...) 9 | end 10 | return out 11 | end 12 | 13 | function join(r,delim,...) 14 | return _join(r, delim, ...) 15 | end 16 | 17 | function cat(r,...) 18 | return _join(r, '', ...) 19 | end 20 | 21 | function echo(r,a) 22 | return a 23 | end 24 | 25 | function len(r, a) 26 | return string.len(a) 27 | end -------------------------------------------------------------------------------- /src/test/lua/test.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";" .. "/Users/chris/projects/cstivers78/aerospike-mod-lua/src/lua/?.lua;" 2 | 3 | -- require('stream') 4 | 5 | 6 | -- 7 | -- Merge two tables. If the keys in the two tables match, then 8 | -- call `merge()` to merge to the values. 9 | -- 10 | function table_merge(t1,t2, merge) 11 | local t3 = {} 12 | if t1 ~= nil then 13 | for k,v in pairs(t1) do 14 | t3[k] = v 15 | end 16 | end 17 | if t2 ~= nil then 18 | for k, v in pairs(t2) do 19 | if t3[k] then 20 | t3[k] = merge(t3[k], t2[k]) 21 | else 22 | t3[k] = v 23 | end 24 | end 25 | end 26 | return t3 27 | end 28 | 29 | -- 30 | -- Generate a range of numbers 31 | -- 32 | function range(start,limit) 33 | local i = start 34 | return function() 35 | if i < limit then 36 | i = i + 1 37 | return i 38 | else 39 | return nil 40 | end 41 | end 42 | end 43 | 44 | -- 45 | -- Generate a values using a function 46 | -- 47 | function generate(limit, fn) 48 | local i = 0 49 | return function() 50 | if i < limit then 51 | return fn() 52 | else 53 | return nil 54 | end 55 | end 56 | end 57 | 58 | -- 59 | -- Iterates over values in an array 60 | -- 61 | function iterator(t) 62 | local i = 0 63 | local n = table.getn(t) 64 | return function() 65 | i = i + 1 66 | if i <= n then return t[i] end 67 | end 68 | end 69 | 70 | 71 | function log(test, desc, stream, stringify) 72 | stringify = stringify or tostring 73 | print(string.format(" [%s] %s", test, desc)) 74 | for v in stream do 75 | print(string.format(" - %s", stringify(v))) 76 | end 77 | end 78 | 79 | function test_integer_sum(i,n) 80 | 81 | local function _map(a) 82 | return a 83 | end 84 | 85 | local function _aggregate(a,b) 86 | return a + (b or 0) 87 | end 88 | 89 | local function _reduce(a,b) 90 | return (a or 0) + (b or 0) 91 | end 92 | 93 | -- ######################################################################## 94 | 95 | print("") 96 | print(string.format("TEST: SUM INTEGERS IN RANGE (%d,%d)",i,n)) 97 | print("") 98 | print(" expected: 5050") 99 | print("") 100 | 101 | local t1 = reduce( range(i,n), _reduce ) 102 | log("t1", "reduce(s)", t1) 103 | 104 | local t2 = aggregate( range(i,n), 0, _aggregate ) 105 | log("t2", "aggregate(s)", t2) 106 | 107 | local t3 = reduce( aggregate( range(i,n), 0, _aggregate ), _reduce ) 108 | log("t3", "reduce(aggregate(s))", t3) 109 | 110 | local s4 = StreamOps.create() : map(_map) : reduce(_reduce) 111 | local t4 = StreamOps.apply( range(i,n), s4, 1) 112 | log("t4", "s : map : reduce", t4) 113 | 114 | local s5 = StreamOps.create() : aggregate(0, _aggregate) : reduce(_reduce) 115 | local t5 = StreamOps.apply( range(i,n), s5, 1) 116 | log("t5", "s : aggregate : reduce", t5) 117 | 118 | 119 | print("") 120 | end 121 | 122 | 123 | 124 | 125 | 126 | 127 | function test_rollup() 128 | 129 | local campaign_views = { 130 | { campaign = "a", views = 1 }, 131 | { campaign = "b", views = 2 }, 132 | { campaign = "c", views = 2 }, 133 | { campaign = "a", views = 2 }, 134 | { campaign = "b", views = 4 }, 135 | { campaign = "c", views = 6 }, 136 | { campaign = "a", views = 3 }, 137 | { campaign = "b", views = 6 }, 138 | { campaign = "c", views = 9 }, 139 | { campaign = "a", views = 4 }, 140 | { campaign = "b", views = 8 }, 141 | { campaign = "c", views = 12 }, 142 | { campaign = "a", views = 5 }, 143 | { campaign = "b", views = 10 }, 144 | { campaign = "c", views = 15 }, 145 | { campaign = "a", views = 6 }, 146 | { campaign = "b", views = 12 }, 147 | { campaign = "c", views = 18 } 148 | } 149 | 150 | local function result_tostring(t) 151 | local s = "{" 152 | local e = false 153 | for k,v in pairs(t) do 154 | if e then 155 | s = s .. ", " 156 | end 157 | s = s .. string.format(" %s = %d", k, v) 158 | e = true 159 | end 160 | s = s .. " }" 161 | return s 162 | end 163 | 164 | -- ######################################################################## 165 | 166 | local function _map(rec) 167 | return { [rec.campaign] = rec.views } 168 | end 169 | 170 | local function _aggregate(agg,rec) 171 | agg[rec.campaign] = (agg[rec.campaign] or 0) + rec.views 172 | return agg 173 | end 174 | 175 | local function _reduce(agg1, agg2) 176 | return table_merge(agg1, agg2, function(v1, v2) 177 | return v1 + v2 178 | end) 179 | end 180 | 181 | -- ######################################################################## 182 | 183 | print("") 184 | print(string.format("TEST: ROLLUP AD IMPRESSIONS")) 185 | print("") 186 | print(" expected: { a = 21, c = 62, b = 42 }") 187 | print("") 188 | 189 | local t1 = aggregate( iterator(campaign_views), {}, _aggregate ) 190 | log("t1", "aggregate(s)", t1, result_tostring) 191 | 192 | local t2 = reduce( aggregate( iterator(campaign_views), {}, _aggregate ), _reduce ) 193 | log("t2", "reduce(aggregate(s))", t2, result_tostring) 194 | 195 | local s3 = StreamOps.create() : aggregate({}, _aggregate) : reduce(_reduce) 196 | local t3 = StreamOps.apply( iterator(campaign_views), s3, 1) 197 | log("t3", "s : aggregate : reduce", t3, result_tostring) 198 | 199 | local s4 = StreamOps.create() : map(_map) : reduce(_reduce) 200 | local t4 = StreamOps.apply( iterator(campaign_views), s4, 1) 201 | log("t4", "s : map : reduce", t4, result_tostring) 202 | 203 | print("") 204 | end 205 | 206 | 207 | 208 | 209 | -- test_integer_sum(0,100) 210 | -- test_rollup() 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /src/test/lua/test_bytes.lua: -------------------------------------------------------------------------------- 1 | 2 | function bytes_create(r, b ) 3 | -- info("bytes create called") 4 | local x = bytes(15) 5 | -- info(" bytes to string is %s",tostring(x)) 6 | local y = bytes.size(x) 7 | return y 8 | end 9 | 10 | function get_set_integer(r, b) 11 | -- info("get set integer test") 12 | 13 | local x = bytes(16) 14 | 15 | bytes.put_int16(x, 0, 4) 16 | bytes.put_int16(x, 2, 8) 17 | bytes.put_int16(x, 4, 0xffff) 18 | 19 | -- info(" buffer is %s",tostring(x)) 20 | 21 | local a1 = bytes.get_int16(x, 0) 22 | local a2 = bytes.get_int16(x, 2) 23 | 24 | -- info("get16: position 0 %s",tostring(a1)) 25 | -- info("get16: position 2 %s",tostring(a2)) 26 | 27 | return "OK" 28 | 29 | end 30 | 31 | function get_set_index(r, b) 32 | 33 | local x = bytes(16) 34 | 35 | x[0] = 1 36 | x[1] = 2 37 | 38 | a1 = x[0] 39 | a2 = x[1] 40 | 41 | -- info(" buffer is %s",tostring(x)) 42 | 43 | -- info("get16: position 0 %s",tostring(a1)) 44 | -- info("get16: position 1 %s",tostring(a2)) 45 | 46 | return "OK" 47 | 48 | end 49 | 50 | function lists_of_bytes(r, b) 51 | 52 | local l = list() 53 | 54 | for i=1, 20 do 55 | local x = bytes(5) 56 | x[1] = i 57 | x[2] = i * 5 58 | x[3] = i * 10 59 | list.append(l,x) 60 | end 61 | 62 | r.b = l 63 | 64 | return "OK" 65 | 66 | end 67 | 68 | -------------------------------------------------------------------------------- /src/test/lua/test_math.lua: -------------------------------------------------------------------------------- 1 | local exports = {} 2 | 3 | function exports.add(a,b) 4 | return a + b 5 | end 6 | 7 | return exports -------------------------------------------------------------------------------- /src/test/lua/test_unit.lua: -------------------------------------------------------------------------------- 1 | 2 | -- function create_bad_syntax(r,b1,v1,b2,v2) 3 | -- rsp = aerospike:create(r); 4 | -- if (rsp) { 5 | -- info("not created "..rsp); 6 | -- } else { 7 | -- info("created"); 8 | -- } 9 | -- r[b1] = v1; 10 | -- r[b2] = v2; 11 | -- aerospike:update(r); 12 | -- end 13 | 14 | -- Should return error because binname too long 15 | function binname_long(r,a) 16 | info("in binname"); 17 | r['bin_with_a_really_long_name'] = "five"; 18 | return aerospike:update(r); 19 | end 20 | 21 | -- Should return runtime error to client 22 | function will_runtime_err(record) 23 | info("in binname again"); 24 | i_dont_exist(record); 25 | return 0; 26 | end 27 | 28 | -- Should allow for many bins 29 | function many_bins(record,count) 30 | aerospike:create(record); 31 | for i = 1, count do 32 | record[i] = i 33 | end 34 | aerospike:update(record); 35 | return 0; 36 | end 37 | 38 | function set_maplist_bins(record,a,b) 39 | -- map{k1="v1",k2="v2"}; 40 | -- record[a] = map(); 41 | -- record[a]["k1"] = "v1"; 42 | -- record[a]["k2"] = "v2"; 43 | info("set_maplist_bins"); 44 | local m = map(); 45 | m["k1"] = "v1"; 46 | m["k2"] = "v2"; 47 | record[a] = m; 48 | local l = list(); 49 | l[0] = "l1"; 50 | l[1] = "l2"; 51 | record[b] = l; 52 | aerospike:update(record); 53 | return "OK" 54 | end 55 | 56 | function get_map_bin(record,a) 57 | local m = record[a]; 58 | return m["k2"]; 59 | end 60 | 61 | function get_list_bin(record,a) 62 | local l = record[a]; 63 | return l[1]; 64 | end 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/test/lua/validate_1.lua: -------------------------------------------------------------------------------- 1 | local a = 1 -------------------------------------------------------------------------------- /src/test/lua/validate_2.lua: -------------------------------------------------------------------------------- 1 | 2 | 3 | funct oof() 4 | end 5 | 6 | -------------------------------------------------------------------------------- /src/test/lua/validate_3.lua: -------------------------------------------------------------------------------- 1 | 2 | function foo() 3 | var : bar 4 | end -------------------------------------------------------------------------------- /src/test/lua/validate_4.lua: -------------------------------------------------------------------------------- 1 | 2 | a.b = c -------------------------------------------------------------------------------- /src/test/lua/validate_5.lua: -------------------------------------------------------------------------------- 1 | 2 | function a(b) 3 | b[c] = d 4 | end 5 | -------------------------------------------------------------------------------- /src/test/lua/validate_6.lua: -------------------------------------------------------------------------------- 1 | 2 | function a(b) 3 | function c.d(e) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /src/test/mod_lua_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include "test.h" 19 | 20 | static bool 21 | before(atf_plan* plan) 22 | { 23 | return cf_clock_init(); 24 | } 25 | 26 | PLAN(mod_lua_test) 27 | { 28 | plan_before(before); 29 | 30 | plan_add(hash_udf); 31 | plan_add(list_udf); 32 | plan_add(record_udf); 33 | plan_add(stream_udf); 34 | plan_add(validation_basics); 35 | } 36 | -------------------------------------------------------------------------------- /src/test/record/record_udf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include "../test.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "../util/test_aerospike.h" 29 | #include "../util/test_logger.h" 30 | #include "../util/map_rec.h" 31 | 32 | /****************************************************************************** 33 | * TEST CASES 34 | *****************************************************************************/ 35 | 36 | TEST(record_udf_1, "echo bin a of {a = 123, b = 456 }") 37 | { 38 | as_rec * rec = map_rec_new(); 39 | as_rec_set(rec, "a", (as_val *) as_integer_new(123)); 40 | 41 | // as_module_apply_record() will decrement ref count and attempt to free, 42 | // so add extra reserve and free later. 43 | as_val_reserve(rec); 44 | 45 | as_arraylist arglist; 46 | as_arraylist_inita(&arglist, 1); 47 | as_arraylist_append_str(&arglist, "a"); 48 | 49 | as_result * res = as_success_new(NULL); 50 | 51 | int rc = as_module_apply_record(&mod_lua, &ctx, "records", "getbin", rec, (as_list *) &arglist, res); 52 | 53 | assert_int_eq(rc, 0); 54 | assert_true(res->is_success); 55 | assert_not_null(res->value); 56 | assert_int_eq(as_integer_toint((as_integer *) res->value), 123); 57 | 58 | as_rec_destroy(rec); 59 | as_arraylist_destroy(&arglist); 60 | as_result_destroy(res); 61 | } 62 | 63 | TEST(record_udf_2, "concat bins a and b of {a = 'abc', b = 'def' }") 64 | { 65 | as_rec * rec = map_rec_new(); 66 | as_rec_set(rec, "a", (as_val *) as_string_new("abc",false)); 67 | as_rec_set(rec, "b", (as_val *) as_string_new("def",false)); 68 | 69 | // as_module_apply_record() will decrement ref count and attempt to free, 70 | // so add extra reserve and free later. 71 | as_val_reserve(rec); 72 | 73 | as_arraylist arglist; 74 | as_arraylist_inita(&arglist, 2); 75 | as_arraylist_append_str(&arglist, "a"); 76 | as_arraylist_append_str(&arglist, "b"); 77 | 78 | as_result * res = as_success_new(NULL); 79 | 80 | int rc = as_module_apply_record(&mod_lua, &ctx, "records", "cat", rec, (as_list *) &arglist, res); 81 | 82 | assert_int_eq(rc, 0); 83 | assert_true(res->is_success); 84 | assert_not_null(res->value); 85 | assert_string_eq(as_string_tostring((as_string *)res->value), "abcdef"); 86 | 87 | as_rec_destroy(rec); 88 | as_arraylist_destroy(&arglist); 89 | as_result_destroy(res); 90 | } 91 | 92 | /****************************************************************************** 93 | * TEST SUITE 94 | *****************************************************************************/ 95 | 96 | SUITE(record_udf, "stream udf tests") 97 | { 98 | suite_before(test_suite_before); 99 | suite_after(test_suite_after); 100 | 101 | suite_add(record_udf_1); 102 | suite_add(record_udf_2); 103 | } 104 | -------------------------------------------------------------------------------- /src/test/stream/stream_udf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include "../test.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "../util/test_aerospike.h" 29 | #include "../util/test_logger.h" 30 | #include "../util/map_rec.h" 31 | #include "../util/producer_stream.h" 32 | #include "../util/consumer_stream.h" 33 | 34 | /****************************************************************************** 35 | * TEST CASES 36 | *****************************************************************************/ 37 | 38 | static uint32_t limit = 0; 39 | static uint32_t produced = 0; 40 | static uint32_t consumed = 0; 41 | 42 | static as_val * produce1(void) 43 | { 44 | if (produced >= limit) { 45 | return AS_STREAM_END; 46 | } 47 | 48 | produced++; 49 | 50 | return (as_val *) as_integer_new(produced); 51 | } 52 | 53 | static as_stream_status consume1(as_val * v) 54 | { 55 | if (v != AS_STREAM_END) { 56 | consumed++; 57 | } 58 | 59 | as_val_destroy(v); 60 | 61 | return AS_STREAM_OK; 62 | } 63 | 64 | TEST(stream_udf_1, "filter even numbers from range (1-10)") 65 | { 66 | 67 | limit = 10; 68 | produced = 0; 69 | consumed = 0; 70 | 71 | as_stream * istream = producer_stream_new(produce1); 72 | as_stream * ostream = consumer_stream_new(consume1); 73 | as_list * arglist = NULL; 74 | 75 | int rc = as_module_apply_stream(&mod_lua, &ctx, "aggr", "even", istream, arglist, ostream,NULL); 76 | 77 | assert_int_eq(rc, 0); 78 | assert_int_eq(produced, limit); 79 | assert_int_eq(consumed, produced / 2); 80 | 81 | as_stream_destroy(istream); 82 | as_stream_destroy(ostream); 83 | } 84 | 85 | TEST(stream_udf_2, "increment range (1-10)") 86 | { 87 | 88 | limit = 10; 89 | produced = 0; 90 | consumed = 0; 91 | 92 | as_stream * istream = producer_stream_new(produce1); 93 | as_stream * ostream = consumer_stream_new(consume1); 94 | as_list * arglist = NULL; 95 | 96 | int rc = as_module_apply_stream(&mod_lua, &ctx, "aggr", "increment", istream, arglist, ostream,NULL); 97 | 98 | assert_int_eq(rc, 0); 99 | assert_int_eq(produced, limit); 100 | assert_int_eq(consumed, produced); 101 | 102 | as_stream_destroy(istream); 103 | as_stream_destroy(ostream); 104 | } 105 | 106 | static as_integer * result3 = NULL; 107 | 108 | static as_val * produce3(void) 109 | { 110 | if (produced >= limit) { 111 | return AS_STREAM_END; 112 | } 113 | 114 | produced++; 115 | 116 | return (as_val *) as_integer_new(produced); 117 | } 118 | 119 | static as_stream_status consume3(as_val * v) 120 | { 121 | if (v != AS_STREAM_END) { 122 | consumed++; 123 | result3 = (as_integer *) v; 124 | } 125 | 126 | return AS_STREAM_OK; 127 | } 128 | 129 | TEST(stream_udf_3, "sum range (1-1,000,000)") 130 | { 131 | limit = 1000 * 1000; 132 | produced = 0; 133 | consumed = 0; 134 | 135 | result3 = NULL; 136 | 137 | as_stream * istream = producer_stream_new(produce3); 138 | as_stream * ostream = consumer_stream_new(consume3); 139 | as_list * arglist = NULL; 140 | 141 | int rc = as_module_apply_stream(&mod_lua, &ctx, "aggr", "sum", istream, arglist, ostream,NULL); 142 | 143 | uint64_t result = (uint64_t) as_integer_get(result3); 144 | 145 | assert_int_eq(rc, 0); 146 | assert_int_eq(produced, limit); 147 | assert_int_eq(consumed, 1); 148 | assert_int_eq(result, 500000500000); 149 | 150 | as_integer_destroy(result3); 151 | as_stream_destroy(istream); 152 | as_stream_destroy(ostream); 153 | } 154 | 155 | TEST(stream_udf_4, "product range (1-10)") 156 | { 157 | 158 | limit = 10; 159 | produced = 0; 160 | consumed = 0; 161 | 162 | result3 = NULL; 163 | 164 | as_stream * istream = producer_stream_new(produce3); 165 | as_stream * ostream = consumer_stream_new(consume3); 166 | as_list * arglist = NULL; 167 | 168 | int rc = as_module_apply_stream(&mod_lua, &ctx, "aggr", "product", istream, arglist, ostream,NULL); 169 | 170 | assert_int_eq(rc, 0); 171 | assert_int_eq(produced, limit); 172 | assert_int_eq(consumed, 1); 173 | assert_int_eq(as_integer_get(result3), 3628800); 174 | 175 | as_integer_destroy(result3); 176 | as_stream_destroy(istream); 177 | as_stream_destroy(ostream); 178 | } 179 | 180 | static as_map * result5 = NULL; 181 | 182 | static as_val * produce5(void) 183 | { 184 | if (produced >= limit) { 185 | return AS_STREAM_END; 186 | } 187 | 188 | produced++; 189 | 190 | as_rec * rec = map_rec_new(); 191 | as_rec_set(rec, "id", (as_val *) as_integer_new(produced)); 192 | as_rec_set(rec, "campaign", (as_val *) as_integer_new(produced % 10)); 193 | as_rec_set(rec, "views", (as_val *) as_integer_new(produced * 2919 % 1000)); 194 | 195 | return (as_val *) rec; 196 | } 197 | 198 | static as_stream_status consume5(as_val * v) 199 | { 200 | if (v != AS_STREAM_END) { 201 | consumed++; 202 | result5 = (as_map *) v; 203 | } 204 | 205 | return AS_STREAM_OK; 206 | } 207 | 208 | TEST(stream_udf_5, "campaign rollup w/ map & reduce") 209 | { 210 | limit = 100; 211 | produced = 0; 212 | consumed = 0; 213 | 214 | result5 = NULL; 215 | 216 | as_stream * istream = producer_stream_new(produce5); 217 | as_stream * ostream = consumer_stream_new(consume5); 218 | as_list * arglist = (as_list *) as_arraylist_new(0,0); 219 | 220 | int rc = as_module_apply_stream(&mod_lua, &ctx, "aggr", "rollup", istream, arglist, ostream,NULL); 221 | 222 | assert_int_eq(rc, 0); 223 | assert_int_eq(produced, limit); 224 | assert_int_eq(consumed, 1); 225 | 226 | as_integer i; 227 | 228 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 0))), 5450); 229 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 1))), 4740); 230 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 2))), 4930); 231 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 3))), 5120); 232 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 4))), 4310); 233 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 5))), 5500); 234 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 6))), 4690); 235 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 7))), 4880); 236 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 8))), 5070); 237 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 9))), 5260); 238 | 239 | as_list_destroy(arglist); 240 | as_map_destroy(result5); 241 | as_stream_destroy(istream); 242 | as_stream_destroy(ostream); 243 | } 244 | 245 | TEST(stream_udf_6, "campaign rollup w/ aggregate") 246 | { 247 | limit = 100; 248 | produced = 0; 249 | consumed = 0; 250 | 251 | result5 = NULL; 252 | 253 | as_stream * istream = producer_stream_new(produce5); 254 | as_stream * ostream = consumer_stream_new(consume5); 255 | as_list * arglist = (as_list *) as_arraylist_new(0,0); 256 | 257 | int rc = as_module_apply_stream(&mod_lua, &ctx, "aggr", "rollup2", istream, arglist, ostream,NULL); 258 | 259 | assert_int_eq(rc, 0); 260 | assert_int_eq(produced, limit); 261 | assert_int_eq(consumed, 1); 262 | 263 | as_integer i; 264 | 265 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 0))), 5450); 266 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 1))), 4740); 267 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 2))), 4930); 268 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 3))), 5120); 269 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 4))), 4310); 270 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 5))), 5500); 271 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 6))), 4690); 272 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 7))), 4880); 273 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 8))), 5070); 274 | assert_int_eq(as_integer_get((as_integer *) as_map_get(result5, (as_val *) as_integer_init(&i, 9))), 5260); 275 | 276 | as_list_destroy(arglist); 277 | as_map_destroy(result5); 278 | as_stream_destroy(istream); 279 | as_stream_destroy(ostream); 280 | } 281 | 282 | /****************************************************************************** 283 | * TEST SUITE 284 | *****************************************************************************/ 285 | 286 | SUITE(stream_udf, "stream udf tests") 287 | { 288 | suite_before(test_suite_before); 289 | suite_after(test_suite_after); 290 | 291 | suite_add(stream_udf_1); 292 | suite_add(stream_udf_2); 293 | suite_add(stream_udf_3); 294 | suite_add(stream_udf_4); 295 | suite_add(stream_udf_5); 296 | suite_add(stream_udf_6); 297 | } 298 | -------------------------------------------------------------------------------- /src/test/test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | /****************************************************************************** 25 | * MACROS 26 | *****************************************************************************/ 27 | 28 | #define ATF_PLAN_SUITE_MAX 128 29 | #define ATF_SUITE_TEST_MAX 128 30 | 31 | /****************************************************************************** 32 | * atf_test 33 | *****************************************************************************/ 34 | 35 | typedef struct atf_test_s atf_test; 36 | typedef struct atf_test_result_s atf_test_result; 37 | 38 | struct atf_test_s { 39 | const char * name; 40 | const char * desc; 41 | void (* run)(atf_test *, atf_test_result *); 42 | }; 43 | 44 | struct atf_test_result_s { 45 | atf_test * test; 46 | bool success; 47 | char message[1024]; 48 | }; 49 | 50 | atf_test_result * atf_test_run(atf_test * test); 51 | 52 | atf_test_result * atf_test_result_new(atf_test * test); 53 | void atf_test_result_destroy(atf_test_result * result); 54 | 55 | #define TEST(__test_name, __test_desc) \ 56 | static void test_spec__##__test_name(atf_test *, atf_test_result *); \ 57 | static atf_test test__##__test_name = { \ 58 | .name = #__test_name, \ 59 | .desc = __test_desc, \ 60 | .run = test_spec__##__test_name \ 61 | }; \ 62 | atf_test * __test_name = & test__##__test_name; \ 63 | static void test_spec__##__test_name(atf_test * self, atf_test_result * __result__) 64 | 65 | /****************************************************************************** 66 | * atf_suite 67 | *****************************************************************************/ 68 | 69 | typedef struct atf_suite_s atf_suite; 70 | typedef struct atf_suite_result_s atf_suite_result; 71 | 72 | struct atf_suite_s { 73 | const char * name; 74 | const char * desc; 75 | atf_test * tests[ATF_SUITE_TEST_MAX]; 76 | uint32_t size; 77 | void (* init)(atf_suite *); 78 | bool (* before)(atf_suite *); 79 | bool (* after)(atf_suite *); 80 | }; 81 | 82 | struct atf_suite_result_s { 83 | atf_suite * suite; 84 | atf_test_result * tests[ATF_SUITE_TEST_MAX]; 85 | uint32_t size; 86 | uint32_t success; 87 | }; 88 | 89 | atf_suite * atf_suite_add(atf_suite * suite, atf_test * test); 90 | uint32_t atf_suite_size(atf_suite * suite); 91 | atf_suite_result * atf_suite_run(atf_suite * suite); 92 | 93 | atf_suite * atf_suite_after(atf_suite * suite, bool (* after)(atf_suite * suite)); 94 | atf_suite * atf_suite_before(atf_suite * suite, bool (* before)(atf_suite * suite)); 95 | 96 | atf_suite_result * atf_suite_result_new(atf_suite * suite); 97 | void atf_suite_result_destroy(atf_suite_result * result); 98 | 99 | atf_suite_result * atf_suite_result_add(atf_suite_result * suite_result, atf_test_result * test_result); 100 | void atf_suite_result_print(atf_suite_result * suite_result); 101 | 102 | #define SUITE(__suite_name, __suite_desc) \ 103 | static void suite_spec__##__suite_name(atf_suite *); \ 104 | static atf_suite suite__##__suite_name = { \ 105 | .name = #__suite_name, \ 106 | .desc = __suite_desc, \ 107 | .tests = {NULL}, \ 108 | .size = 0, \ 109 | .init = suite_spec__##__suite_name, \ 110 | .before = NULL, \ 111 | .after = NULL \ 112 | }; \ 113 | atf_suite * __suite_name = & suite__##__suite_name; \ 114 | static void suite_spec__##__suite_name(atf_suite * self) 115 | 116 | #define suite_add(__test) \ 117 | atf_suite_add(self, __test) 118 | 119 | #define suite_before(__func) \ 120 | atf_suite_before(self, __func) 121 | 122 | #define suite_after(__func) \ 123 | atf_suite_after(self, __func) 124 | 125 | 126 | /****************************************************************************** 127 | * atf_plan 128 | *****************************************************************************/ 129 | 130 | typedef struct atf_plan_s atf_plan; 131 | typedef struct atf_plan_result_s atf_plan_result; 132 | 133 | struct atf_plan_s { 134 | const char * name; 135 | atf_suite * suites[ATF_PLAN_SUITE_MAX]; 136 | uint32_t size; 137 | bool (* before)(atf_plan *); 138 | bool (* after)(atf_plan *); 139 | }; 140 | 141 | struct atf_plan_result_s { 142 | atf_plan * plan; 143 | atf_suite_result * suites[ATF_PLAN_SUITE_MAX]; 144 | uint32_t size; 145 | }; 146 | 147 | atf_plan * atf_plan_add(atf_plan * self, atf_suite * suite); 148 | int atf_plan_run(atf_plan * self, atf_plan_result * result); 149 | void atf_plan_result_destroy(atf_plan_result * result); 150 | 151 | atf_plan * atf_plan_after(atf_plan * plan, bool (* after)(atf_plan * plan)); 152 | atf_plan * atf_plan_before(atf_plan * plan, bool (* before)(atf_plan * plan)); 153 | 154 | atf_plan_result * atf_plan_result_add(atf_plan_result * plan_result, atf_suite_result * suite_result); 155 | 156 | #define PLAN(__plan_name)\ 157 | static void plan_spec__##__plan_name(atf_plan * self); \ 158 | static atf_plan plan__##__plan_name = { \ 159 | .name = #__plan_name, \ 160 | .suites = {NULL}, \ 161 | .size = 0, \ 162 | .before = NULL, \ 163 | .after = NULL \ 164 | }; \ 165 | atf_plan * __plan_name = & plan__##__plan_name; \ 166 | int main(int argc, char ** args) { \ 167 | atf_plan atfp = {#__plan_name}; \ 168 | atf_plan_result result = { \ 169 | .plan = &atfp, \ 170 | .suites = { NULL }, \ 171 | .size = 0 \ 172 | }; \ 173 | plan_spec__##__plan_name(__plan_name); \ 174 | return atf_plan_run(__plan_name, &result); \ 175 | }\ 176 | static void plan_spec__##__plan_name(atf_plan * self) \ 177 | 178 | 179 | #define plan_add(__suite) \ 180 | extern atf_suite * __suite; \ 181 | atf_plan_add(self, __suite) 182 | 183 | #define plan_before(__func) \ 184 | atf_plan_before(self, __func) 185 | 186 | #define plan_after(__func) \ 187 | atf_plan_after(self, __func) 188 | 189 | /****************************************************************************** 190 | * atf_assert 191 | *****************************************************************************/ 192 | 193 | void atf_assert(atf_test_result * test_result, const char * exp, const char * file, int line); 194 | 195 | void atf_assert_true(atf_test_result * test_result, const char * exp, const char * file, int line); 196 | void atf_assert_false(atf_test_result * test_result, const char * exp, const char * file, int line); 197 | 198 | void atf_assert_null(atf_test_result * test_result, const char * exp, const char * file, int line); 199 | void atf_assert_not_null(atf_test_result * test_result, const char * exp, const char * file, int line); 200 | 201 | void atf_assert_int_eq(atf_test_result * result, const char * actual_exp, int64_t actual, int64_t expected, const char * file, int line); 202 | void atf_assert_int_ne(atf_test_result * result, const char * actual_exp, int64_t actual, int64_t expected, const char * file, int line); 203 | 204 | void atf_assert_double_eq(atf_test_result * result, const char * actual_exp, double actual, double expected, const char * file, int line); 205 | 206 | void atf_assert_string_eq(atf_test_result * result, const char * actual_exp, const char * actual, const char * expected, const char * file, int line); 207 | 208 | void atf_assert_log(atf_test_result * result, const char * exp, const char * file, int line, const char * fmt, ...); 209 | 210 | 211 | #define assert(EXP) \ 212 | if ( (EXP) != true ) return atf_assert(__result__, #EXP, __FILE__, __LINE__); 213 | 214 | #define assert_true(EXP) \ 215 | if ( (EXP) != true ) return atf_assert_true(__result__, #EXP, __FILE__, __LINE__); 216 | 217 | #define assert_false(EXP) \ 218 | if ( (EXP) == true ) return atf_assert_false(__result__, #EXP, __FILE__, __LINE__); 219 | 220 | #define assert_null(EXP) \ 221 | if ( (EXP) != NULL ) return atf_assert_null(__result__, #EXP, __FILE__, __LINE__); 222 | 223 | #define assert_not_null(EXP) \ 224 | if ( (EXP) == NULL ) return atf_assert_not_null(__result__, #EXP, __FILE__, __LINE__); 225 | 226 | 227 | #define assert_int_eq(ACTUAL, EXPECTED) \ 228 | if ( (ACTUAL) != (EXPECTED) ) return atf_assert_int_eq(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__); 229 | 230 | #define assert_int_ne(ACTUAL, EXPECTED) \ 231 | if ( (ACTUAL) == (EXPECTED) ) return atf_assert_int_ne(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__); 232 | 233 | #define assert_double_eq(ACTUAL, EXPECTED) \ 234 | if ( (ACTUAL) != (EXPECTED) ) return atf_assert_double_eq(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__); 235 | 236 | #define assert_string_eq(ACTUAL, EXPECTED) \ 237 | if ( strcmp(ACTUAL, EXPECTED) != 0 ) return atf_assert_string_eq(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__); 238 | 239 | 240 | #define assert_log(EXP, fmt, ...) \ 241 | if ( (EXP) == true ) return atf_assert_log(__result__, #EXP, __FILE__, __LINE__, fmt, ##__VA_ARGS__ ); 242 | 243 | /****************************************************************************** 244 | * atf_log 245 | *****************************************************************************/ 246 | 247 | #define ATF_LOG_PREFIX " " 248 | 249 | #define debug(fmt, ...) \ 250 | atf_log_line(stderr, "DEBUG", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ##__VA_ARGS__); 251 | 252 | #define info(fmt, ...) \ 253 | atf_log(stderr, "INFO", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ##__VA_ARGS__); 254 | 255 | #define warn(fmt, ...) \ 256 | atf_log(stderr, "WARN", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ##__VA_ARGS__); 257 | 258 | #define error(fmt, ...) \ 259 | atf_log(stderr, "ERROR", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ##__VA_ARGS__); 260 | 261 | void atf_log(FILE * f, const char * level, const char * prefix, const char * file, int line, const char * fmt, ...); 262 | 263 | void atf_log_line(FILE * f, const char * level, const char * prefix, const char * file, int line, const char * fmt, ...); 264 | 265 | void atf_log_linev(FILE * f, const char * level, const char * prefix, const char * file, int line, const char * fmt, va_list ap); 266 | -------------------------------------------------------------------------------- /src/test/util/consumer_stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | /** 19 | * A stream which consumes values via a callback. 20 | */ 21 | 22 | #include "consumer_stream.h" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | /***************************************************************************** 30 | * STATIC FUNCTIONS 31 | *****************************************************************************/ 32 | 33 | static as_stream_status consumer_stream_write(const as_stream *, as_val *); 34 | 35 | /***************************************************************************** 36 | * CONSTANTS 37 | *****************************************************************************/ 38 | 39 | static const as_stream_hooks consumer_stream_hooks = { 40 | .destroy = NULL, 41 | .read = NULL, 42 | .write = consumer_stream_write 43 | }; 44 | 45 | /***************************************************************************** 46 | * FUNCTIONS 47 | *****************************************************************************/ 48 | 49 | as_stream * consumer_stream_new(consumer_callback f) 50 | { 51 | return as_stream_new(f, &consumer_stream_hooks); 52 | } 53 | 54 | as_stream * consumer_stream_init(as_stream * s, consumer_callback f) 55 | { 56 | return as_stream_init(s, f, &consumer_stream_hooks); 57 | } 58 | 59 | static as_stream_status consumer_stream_write(const as_stream * s, as_val * v) 60 | { 61 | consumer_callback f = (consumer_callback) as_stream_source(s); 62 | return f(v); 63 | } 64 | -------------------------------------------------------------------------------- /src/test/util/consumer_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | /** 21 | * A stream which consumes values via a callback. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | /***************************************************************************** 28 | * TYPES 29 | *****************************************************************************/ 30 | 31 | typedef as_stream_status (* consumer_callback)(as_val *); 32 | 33 | /***************************************************************************** 34 | * FUNCTIONS 35 | *****************************************************************************/ 36 | 37 | as_stream * consumer_stream_new(consumer_callback); 38 | as_stream * consumer_stream_init(as_stream *, consumer_callback); 39 | -------------------------------------------------------------------------------- /src/test/util/map_rec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include "map_rec.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /***************************************************************************** 26 | * STATIC FUNCTIONS 27 | *****************************************************************************/ 28 | 29 | static bool map_rec_destroy(as_rec *); 30 | static as_val * map_rec_get(const as_rec *, const char *); 31 | static int map_rec_set(const as_rec *, const char *, const as_val *); 32 | static int map_rec_remove(const as_rec *, const char *); 33 | static uint32_t map_rec_ttl(const as_rec *); 34 | static uint16_t map_rec_gen(const as_rec *); 35 | static uint32_t map_rec_hash(const as_rec *); 36 | 37 | /***************************************************************************** 38 | * CONSTANTS 39 | *****************************************************************************/ 40 | 41 | const as_rec_hooks map_rec_hooks = { 42 | .get = map_rec_get, 43 | .set = map_rec_set, 44 | .destroy = map_rec_destroy, 45 | .remove = map_rec_remove, 46 | .ttl = map_rec_ttl, 47 | .gen = map_rec_gen, 48 | .hashcode = map_rec_hash 49 | }; 50 | 51 | /***************************************************************************** 52 | * FUNCTIONS 53 | *****************************************************************************/ 54 | 55 | as_rec * map_rec_new() 56 | { 57 | as_map * m = (as_map *) as_hashmap_new(32); 58 | return as_rec_new(m, &map_rec_hooks); 59 | } 60 | 61 | as_rec * map_rec_init(as_rec * r) 62 | { 63 | as_map * m = (as_map *) as_hashmap_new(32); 64 | return as_rec_init(r, m, &map_rec_hooks); 65 | } 66 | 67 | static bool map_rec_destroy(as_rec * r) 68 | { 69 | as_map * m = (as_map *) r->data; 70 | as_map_destroy(m); 71 | r->data = NULL; 72 | return true; 73 | } 74 | 75 | static as_val * map_rec_get(const as_rec * r, const char * name) 76 | { 77 | as_map * m = (as_map *) r->data; 78 | as_string s; 79 | as_string_init(&s, (char *) name, false); 80 | as_val * v = as_map_get(m, (as_val *) &s); 81 | as_string_destroy(&s); 82 | return v; 83 | } 84 | 85 | static int map_rec_set(const as_rec * r, const char * name, const as_val * value) 86 | { 87 | as_map * m = (as_map *) r->data; 88 | return as_map_set(m, (as_val *) as_string_new(cf_strdup(name),true), (as_val *) value); 89 | } 90 | 91 | static int map_rec_remove(const as_rec * r, const char * name) 92 | { 93 | return 0; 94 | } 95 | 96 | static uint32_t map_rec_ttl(const as_rec * r) 97 | { 98 | return 0; 99 | } 100 | 101 | static uint16_t map_rec_gen(const as_rec * r) 102 | { 103 | return 0; 104 | } 105 | 106 | static uint32_t map_rec_hash(const as_rec * r) 107 | { 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /src/test/util/map_rec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2022 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | /** 21 | * An as_rec backed by a map. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | /***************************************************************************** 28 | * FUNCTIONS 29 | *****************************************************************************/ 30 | 31 | as_rec * map_rec_new(void); 32 | as_rec * map_rec_init(as_rec *); 33 | -------------------------------------------------------------------------------- /src/test/util/producer_stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | /** 19 | * A stream which produces values via a callback. 20 | */ 21 | 22 | #include "producer_stream.h" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | /***************************************************************************** 30 | * STATIC FUNCTIONS 31 | *****************************************************************************/ 32 | 33 | static as_val * producer_stream_read(const as_stream *); 34 | 35 | /***************************************************************************** 36 | * CONSTANTS 37 | *****************************************************************************/ 38 | 39 | static const as_stream_hooks producer_stream_hooks = { 40 | .destroy = NULL, 41 | .read = producer_stream_read, 42 | .write = NULL 43 | }; 44 | 45 | /***************************************************************************** 46 | * FUNCTIONS 47 | *****************************************************************************/ 48 | 49 | as_stream * producer_stream_new(producer_callback f) 50 | { 51 | return as_stream_new(f, &producer_stream_hooks); 52 | } 53 | 54 | as_stream * producer_stream_init(as_stream * s, producer_callback f) 55 | { 56 | return as_stream_init(s, f, &producer_stream_hooks); 57 | } 58 | 59 | static as_val * producer_stream_read(const as_stream * s) 60 | { 61 | producer_callback f = (producer_callback) as_stream_source(s); 62 | return f(); 63 | } 64 | -------------------------------------------------------------------------------- /src/test/util/producer_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2022 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | /** 21 | * A stream which produces values via a callback. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | /***************************************************************************** 28 | * TYPES 29 | *****************************************************************************/ 30 | 31 | typedef as_val * (* producer_callback)(void); 32 | 33 | /***************************************************************************** 34 | * FUNCTIONS 35 | *****************************************************************************/ 36 | 37 | as_stream * producer_stream_new(producer_callback); 38 | as_stream * producer_stream_init(as_stream *, producer_callback); 39 | -------------------------------------------------------------------------------- /src/test/util/test_aerospike.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../test.h" 22 | #include "../util/test_logger.h" 23 | #include "test_aerospike.h" 24 | #include 25 | #include 26 | #include 27 | 28 | /***************************************************************************** 29 | * GLOBALS 30 | *****************************************************************************/ 31 | 32 | as_aerospike as; 33 | as_udf_context ctx; 34 | 35 | /***************************************************************************** 36 | * STATIC FUNCTIONS 37 | *****************************************************************************/ 38 | 39 | static int test_aerospike_log(const as_aerospike * as, const char * file, const int line, const int level, const char * msg); 40 | 41 | /***************************************************************************** 42 | * CONSTANTS 43 | *****************************************************************************/ 44 | 45 | static const as_aerospike_hooks test_aerospike_hooks = { 46 | .destroy = NULL, 47 | .rec_create = NULL, 48 | .rec_update = NULL, 49 | .rec_remove = NULL, 50 | .rec_exists = NULL, 51 | .log = test_aerospike_log, 52 | }; 53 | 54 | /***************************************************************************** 55 | * STATIC FUNCTIONS 56 | *****************************************************************************/ 57 | 58 | as_aerospike* 59 | test_aerospike_new() 60 | { 61 | return as_aerospike_new(NULL, &test_aerospike_hooks); 62 | } 63 | 64 | as_aerospike* 65 | test_aerospike_init(as_aerospike * a) 66 | { 67 | return as_aerospike_init(a, NULL, &test_aerospike_hooks); 68 | } 69 | 70 | static int 71 | test_aerospike_log(const as_aerospike * as, const char * file, const int line, const int level, const char * msg) 72 | { 73 | char l[10] = {'\0'}; 74 | switch(level) { 75 | case 1: 76 | strncpy(l,"WARN",10); 77 | break; 78 | case 2: 79 | strncpy(l,"INFO",10); 80 | break; 81 | case 3: 82 | strncpy(l,"DEBUG",10); 83 | break; 84 | default: 85 | strncpy(l,"TRACE",10); 86 | break; 87 | } 88 | atf_log_line(stderr, l, ATF_LOG_PREFIX, file, line, msg); 89 | return 0; 90 | } 91 | 92 | bool 93 | test_suite_before(atf_suite* suite) 94 | { 95 | test_aerospike_init(&as); 96 | ctx.as = &as; 97 | 98 | mod_lua_config config = { 99 | .server_mode = true, 100 | .cache_enabled = false, 101 | .user_path = AS_START_DIR "src/test/lua" 102 | }; 103 | 104 | as_lua_log_init(); 105 | 106 | int rc = as_module_configure(&mod_lua, &config); 107 | 108 | if (rc != 0) { 109 | error("as_module_configure failed: %d", rc); 110 | return false; 111 | } 112 | return true; 113 | } 114 | 115 | bool 116 | test_suite_after(atf_suite* suite) 117 | { 118 | return true; 119 | } 120 | -------------------------------------------------------------------------------- /src/test/util/test_aerospike.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2022 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | /***************************************************************************** 22 | * GLOBALS 23 | *****************************************************************************/ 24 | 25 | extern as_udf_context ctx; 26 | 27 | #if !defined(_MSC_VER) 28 | #define AS_START_DIR "./" 29 | #else 30 | #define AS_START_DIR "../../" 31 | #endif 32 | 33 | /***************************************************************************** 34 | * FUNCTIONS 35 | *****************************************************************************/ 36 | 37 | as_aerospike* 38 | test_aerospike_new(void); 39 | 40 | as_aerospike* 41 | test_aerospike_init(as_aerospike *); 42 | 43 | bool 44 | test_suite_before(atf_suite* suite); 45 | 46 | bool 47 | test_suite_after(atf_suite* suite); 48 | -------------------------------------------------------------------------------- /src/test/util/test_logger.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #include "test_logger.h" 19 | #include 20 | #include "../test.h" 21 | 22 | static bool 23 | as_lua_log_callback(as_log_level level, const char * func, const char * file, uint32_t line, const char * fmt, ...) 24 | { 25 | va_list ap; 26 | va_start(ap, fmt); 27 | atf_log_linev(stderr, as_log_level_tostring(level), ATF_LOG_PREFIX, file, line, fmt, ap); 28 | va_end(ap); 29 | return true; 30 | } 31 | 32 | void 33 | as_lua_log_init() 34 | { 35 | as_log_set_level(AS_LOG_LEVEL_INFO); 36 | as_log_set_callback(as_lua_log_callback); 37 | } 38 | -------------------------------------------------------------------------------- /src/test/util/test_logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2022 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | void 21 | as_lua_log_init(void); 22 | -------------------------------------------------------------------------------- /src/test/validation/validation_basics.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2018 Aerospike, Inc. 3 | * 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor 5 | * license agreements. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | * use this file except in compliance with the License. You may obtain a copy of 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "../test.h" 35 | #include "../util/test_aerospike.h" 36 | #include "../util/test_logger.h" 37 | #include "../util/map_rec.h" 38 | 39 | /****************************************************************************** 40 | * VARIABLES 41 | *****************************************************************************/ 42 | 43 | typedef struct { 44 | char * filename; 45 | char * description; 46 | bool is_valid; 47 | } validation_entry; 48 | 49 | #define SCRIPT_LEN_MAX 1048576 50 | 51 | static int readfile(const char * filename, char ** content, uint32_t * size) { 52 | 53 | uint8_t * content_v = content ? (uint8_t *) *content : NULL; 54 | uint32_t size_v = size ? (uint32_t) *size : 0; 55 | 56 | FILE * file = fopen(filename,"r"); 57 | 58 | if (!file) { 59 | error("cannot open script file %s : %s", filename, strerror(errno)); 60 | return -1; 61 | } 62 | 63 | if (content_v == NULL) { 64 | content_v = (uint8_t *) cf_malloc(SCRIPT_LEN_MAX); 65 | if (content_v == NULL) { 66 | error("cf_malloc failed"); 67 | fclose(file); 68 | return -2; 69 | } 70 | } 71 | 72 | uint32_t size_b = 0; 73 | 74 | uint8_t * buff = content_v; 75 | int read = (int)fread(buff, 1, 512, file); 76 | while (read) { 77 | size_b += read; 78 | buff += read; 79 | read = (int)fread(buff, 1, 512, file); 80 | if (size_b >= size_v-1) { 81 | break; 82 | } 83 | } 84 | fclose(file); 85 | 86 | content_v[size_b] = '\0'; 87 | 88 | *content = (char *) content_v; 89 | *size = size_b; 90 | 91 | return 0; 92 | } 93 | 94 | /****************************************************************************** 95 | * TEST CASES 96 | *****************************************************************************/ 97 | 98 | TEST(validation_basics_1, "validation: src/test/lua/validate_*.lua") 99 | { 100 | validation_entry entries[] = { 101 | { AS_START_DIR "src/test/lua/validate_1.lua", "single file local variable", true }, 102 | { AS_START_DIR "src/test/lua/validate_2.lua", "invalid function in module scope", false }, 103 | { AS_START_DIR "src/test/lua/validate_3.lua", "invalid statement in function scope", false }, 104 | { AS_START_DIR "src/test/lua/validate_4.lua", "index a global variable in module scope", false }, 105 | { AS_START_DIR "src/test/lua/validate_5.lua", "index a global variable in function scope", true }, 106 | { AS_START_DIR "src/test/lua/validate_6.lua", "create closure on a global variable in function scope", true }, 107 | { NULL } 108 | }; 109 | 110 | for(validation_entry * entry = entries; entry != NULL && entry->filename != NULL; entry++) { 111 | 112 | info("validating %s [%s] - %s", entry->filename, entry->is_valid ? "VALID" : "INVALID", entry->description); 113 | 114 | as_module_error err; 115 | int rc = 0; 116 | 117 | char * buff = NULL; 118 | uint32_t size = 0; 119 | 120 | rc = readfile(entry->filename, &buff, &size); 121 | assert(rc == 0); 122 | 123 | rc = as_module_validate(&mod_lua, ctx.as, entry->filename, buff, size, &err); 124 | cf_free(buff); 125 | 126 | if (rc != 0 && entry->is_valid) { 127 | info("error = {"); 128 | info(" scope = %d", err.scope); 129 | info(" code = %d", err.code); 130 | info(" message = %s", err.message); 131 | info(" file = %s", err.file); 132 | info(" line = %d", err.line); 133 | info(" func = %s", err.func); 134 | info("}"); 135 | assert(rc == 0 && entry->is_valid); 136 | } 137 | 138 | if (rc == 0 && !entry->is_valid) { 139 | assert(rc != 0 && !entry->is_valid); 140 | } 141 | } 142 | } 143 | 144 | /****************************************************************************** 145 | * TEST SUITE 146 | *****************************************************************************/ 147 | 148 | SUITE(validation_basics, "record basics") 149 | { 150 | suite_before(test_suite_before); 151 | 152 | suite_add(validation_basics_1); 153 | } 154 | -------------------------------------------------------------------------------- /vs/aerospike-mod-lua-test/aerospike-mod-lua-test.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {f1554c15-d9f6-48fd-a827-58683e769c4c} 38 | 39 | 40 | 41 | 42 | 43 | 44 | {6E32762B-3CA9-417F-BDC4-9C0BE0A8D6E9} 45 | Win32Proj 46 | aerospikemodluatest 47 | 10.0 48 | 49 | 50 | 51 | Application 52 | true 53 | v143 54 | 55 | 56 | Application 57 | false 58 | v143 59 | true 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | true 79 | 80 | 81 | false 82 | 83 | 84 | 85 | 86 | 87 | Level3 88 | Disabled 89 | 90 | 91 | Console 92 | true 93 | 94 | 95 | XCOPY ..\..\..\aerospike-client-c\vs\packages\aerospike-client-c-dependencies.1.0.1\build\native\lib\x64\$(Configuration)\*.dll "$(TargetDir)" /D /K /Y 96 | 97 | 98 | 99 | 100 | Level3 101 | 102 | 103 | MaxSpeed 104 | true 105 | true 106 | 107 | 108 | Console 109 | true 110 | true 111 | true 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /vs/aerospike-mod-lua-test/aerospike-mod-lua-test.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {965edf08-4d07-45e9-90f7-707883a453e3} 18 | 19 | 20 | {f16b0276-4b22-49c2-9f54-125d98d54979} 21 | 22 | 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files\util 29 | 30 | 31 | Header Files\util 32 | 33 | 34 | Header Files\util 35 | 36 | 37 | Header Files\util 38 | 39 | 40 | Header Files\util 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files\util 52 | 53 | 54 | Source Files\util 55 | 56 | 57 | Source Files\util 58 | 59 | 60 | Source Files\util 61 | 62 | 63 | Source Files\util 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /vs/aerospike-mod-lua-test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /vs/aerospike-mod-lua.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33213.308 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aerospike-mod-lua", "aerospike-mod-lua\aerospike-mod-lua.vcxproj", "{F1554C15-D9F6-48FD-A827-58683E769C4C}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aerospike-mod-lua-test", "aerospike-mod-lua-test\aerospike-mod-lua-test.vcxproj", "{6E32762B-3CA9-417F-BDC4-9C0BE0A8D6E9}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F1554C15-D9F6-48FD-A827-58683E769C4C}.Debug|x64.ActiveCfg = Debug|x64 17 | {F1554C15-D9F6-48FD-A827-58683E769C4C}.Debug|x64.Build.0 = Debug|x64 18 | {F1554C15-D9F6-48FD-A827-58683E769C4C}.Release|x64.ActiveCfg = Release|x64 19 | {F1554C15-D9F6-48FD-A827-58683E769C4C}.Release|x64.Build.0 = Release|x64 20 | {6E32762B-3CA9-417F-BDC4-9C0BE0A8D6E9}.Debug|x64.ActiveCfg = Debug|x64 21 | {6E32762B-3CA9-417F-BDC4-9C0BE0A8D6E9}.Debug|x64.Build.0 = Debug|x64 22 | {6E32762B-3CA9-417F-BDC4-9C0BE0A8D6E9}.Release|x64.ActiveCfg = Release|x64 23 | {6E32762B-3CA9-417F-BDC4-9C0BE0A8D6E9}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {4234EE2E-1C91-407F-BF87-70CC8D73F412} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /vs/aerospike-mod-lua/aerospike-mod-lua.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | {F1554C15-D9F6-48FD-A827-58683E769C4C} 47 | Win32Proj 48 | aerospikemodlua 49 | 10.0 50 | 51 | 52 | 53 | StaticLibrary 54 | true 55 | v143 56 | 57 | 58 | StaticLibrary 59 | false 60 | v143 61 | true 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | Level3 84 | Disabled 85 | 86 | 87 | Windows 88 | 89 | 90 | 91 | 92 | Level3 93 | 94 | 95 | MaxSpeed 96 | true 97 | true 98 | 99 | 100 | Windows 101 | true 102 | true 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /vs/aerospike-mod-lua/aerospike-mod-lua.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {61f4848d-4dc4-4d77-a67c-f77e246cf0ee} 18 | 19 | 20 | 21 | 22 | Header Files\aerospike 23 | 24 | 25 | Header Files\aerospike 26 | 27 | 28 | Header Files\aerospike 29 | 30 | 31 | Header Files\aerospike 32 | 33 | 34 | Header Files\aerospike 35 | 36 | 37 | Header Files\aerospike 38 | 39 | 40 | Header Files\aerospike 41 | 42 | 43 | Header Files\aerospike 44 | 45 | 46 | Header Files\aerospike 47 | 48 | 49 | Header Files\aerospike 50 | 51 | 52 | Header Files\aerospike 53 | 54 | 55 | Header Files\aerospike 56 | 57 | 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | Source Files 91 | 92 | 93 | Source Files 94 | 95 | 96 | Source Files 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /vs/aerospike-mod-lua/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /vs/props/base.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ..\..\src\include;..\..\..\aerospike-common\src\include;..\..\..\aerospike-client-c\vs\packages\aerospike-client-c-dependencies.1.0.0\build\native\include;$(IncludePath) 7 | 8 | 9 | 10 | _CRT_SECURE_NO_DEPRECATE;_TIMESPEC_DEFINED;%(PreprocessorDefinitions) 11 | 4098;%(DisableSpecificWarnings) 12 | 13 | 14 | 15 | 16 | $(SolutionDir)x64\$(Configuration);..\..\..\aerospike-client-c\vs\lib;..\..\..\aerospike-client-c\vs\packages\aerospike-client-c-dependencies.1.0.0\build\native\lib\x64\$(Configuration);%(AdditionalLibraryDirectories) 17 | pthreadVC2d.lib;lua51.lib;%(AdditionalDependencies) 18 | 19 | 20 | 21 | 22 | $(SolutionDir)x64\$(Configuration);..\..\..\aerospike-client-c\vs\lib;..\..\..\aerospike-client-c\vs\packages\aerospike-client-c-dependencies.1.0.0\build\native\lib\x64\$(Configuration);%(AdditionalLibraryDirectories) 23 | pthreadVC2.lib;lua51.lib;%(AdditionalDependencies) 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /vs/props/test.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | *.dll;$(ExtensionsToDeleteOnClean) 7 | 8 | 9 | 10 | XCOPY ..\..\..\aerospike-client-c\vs\packages\aerospike-client-c-dependencies.1.0.0\build\native\lib\x64\$(Configuration)\*.dll "$(TargetDir)" /D /K /Y 11 | 12 | 13 | 14 | 15 | Copy DLLs to Target Directory 16 | 17 | 18 | ..\..\..\aerospike-common\vs\x64\$(Configuration);%(AdditionalLibraryDirectories) 19 | aerospike-mod-lua.lib;aerospike-common.lib;%(AdditionalDependencies) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /xcode/aerospike-mod-lua.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /xcode/aerospike-mod-lua.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /xcode/aerospike-mod-lua.xcworkspace/xcshareddata/aerospike-mod-lua.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "51F8DF67304F280D6DE1D6D5537A5AE5C0054730" : 9223372036854775807, 8 | "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B" : 9223372036854775807 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "2B765FB4-C550-4774-914E-D94F5CCD7C2C", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "51F8DF67304F280D6DE1D6D5537A5AE5C0054730" : "common\/", 13 | "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B" : "mod-lua\/" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "aerospike-mod-lua", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "xcode\/aerospike-mod-lua.xcworkspace", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/citrusleaf\/aerospike-common.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "51F8DF67304F280D6DE1D6D5537A5AE5C0054730" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/citrusleaf\/aerospike-mod-lua.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /xcode/aerospike-mod-lua.xcworkspace/xcshareddata/mod-lua.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "51F8DF67304F280D6DE1D6D5537A5AE5C0054730" : 0, 8 | "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B" : 0 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "6E7D99B1-B2BA-4CBC-8647-B276DD012FA7", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "51F8DF67304F280D6DE1D6D5537A5AE5C0054730" : "common\/", 13 | "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B" : "mod-lua\/" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "mod-lua", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "project\/mod-lua.xcworkspace", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/citrusleaf\/aerospike-common.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "51F8DF67304F280D6DE1D6D5537A5AE5C0054730" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/citrusleaf\/aerospike-mod-lua.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "7CDD612D83226CD2A53C473AC2BFE3114D9AE12B" 28 | } 29 | ] 30 | } --------------------------------------------------------------------------------