fix compile error
This commit is contained in:
parent
0010927964
commit
34b2f7b8f8
|
@ -570,7 +570,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
|
||||||
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
|
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
|
||||||
/* skip eventual `#!...' */
|
/* skip eventual `#!...' */
|
||||||
while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
|
while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
|
||||||
lf.extraline = 0;
|
lf.extraline = 0;
|
||||||
}
|
}
|
||||||
ungetc(c, lf.f);
|
ungetc(c, lf.f);
|
||||||
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
||||||
|
|
|
@ -107,7 +107,7 @@ int taosLoadScriptInit(SUdfInit* pInit) {
|
||||||
pInit->destroyCtxFunc = destroyScriptCtx;
|
pInit->destroyCtxFunc = destroyScriptCtx;
|
||||||
|
|
||||||
ScriptCtx *pCtx = pInit->script_ctx;
|
ScriptCtx *pCtx = pInit->script_ctx;
|
||||||
char funcName[MAX_FUNC_NAME] = {0};
|
char funcName[MAX_FUNC_NAME + 10] = {0};
|
||||||
sprintf(funcName, "%s_init", pCtx->funcName);
|
sprintf(funcName, "%s_init", pCtx->funcName);
|
||||||
|
|
||||||
lua_State* lua = pCtx->pEnv->lua_state;
|
lua_State* lua = pCtx->pEnv->lua_state;
|
||||||
|
@ -129,7 +129,7 @@ int taosLoadScriptNormal(char *pInput, int16_t iType, int16_t iBytes, int32_t nu
|
||||||
int16_t oType, int16_t oBytes, SUdfInit *pInit) {
|
int16_t oType, int16_t oBytes, SUdfInit *pInit) {
|
||||||
ScriptCtx* pCtx = pInit->script_ctx;
|
ScriptCtx* pCtx = pInit->script_ctx;
|
||||||
|
|
||||||
char funcName[MAX_FUNC_NAME] = {0};
|
char funcName[MAX_FUNC_NAME + 10] = {0};
|
||||||
sprintf(funcName, "%s_add", pCtx->funcName);
|
sprintf(funcName, "%s_add", pCtx->funcName);
|
||||||
lua_State* lua = pCtx->pEnv->lua_state;
|
lua_State* lua = pCtx->pEnv->lua_state;
|
||||||
lua_getglobal(lua, funcName);
|
lua_getglobal(lua, funcName);
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
typedef struct SUdfInit{
|
||||||
|
int maybe_null; /* 1 if function can return NULL */
|
||||||
|
int decimals; /* for real functions */
|
||||||
|
long long length; /* For string functions */
|
||||||
|
char *ptr; /* free pointer for function data */
|
||||||
|
int const_item; /* 0 if result is independent of arguments */
|
||||||
|
} SUdfInit;
|
||||||
|
|
||||||
|
typedef struct SDemo{
|
||||||
|
double sum;
|
||||||
|
int num;
|
||||||
|
short otype;
|
||||||
|
}SDemo;
|
||||||
|
|
||||||
|
void demo(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* tsOutput,
|
||||||
|
int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
|
||||||
|
int i;
|
||||||
|
double r = 0;
|
||||||
|
SDemo *p = (SDemo *)buf->ptr;
|
||||||
|
printf("demo input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
|
||||||
|
|
||||||
|
for(i=0;i<numOfRows;++i) {
|
||||||
|
if (itype == 6) {
|
||||||
|
r=*((float *)data+i);
|
||||||
|
} else if (itype == 7) {
|
||||||
|
r=*((double *)data+i);
|
||||||
|
}
|
||||||
|
|
||||||
|
p->sum += r*r;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->otype = otype;
|
||||||
|
p->num += numOfRows;
|
||||||
|
|
||||||
|
*numOfOutput=1;
|
||||||
|
|
||||||
|
printf("demo out, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void demo_finalize(char* dataOutput, int* numOfOutput, SUdfInit* buf) {
|
||||||
|
SDemo *p = (SDemo *)buf->ptr;
|
||||||
|
printf("demo_finalize dataoutput:%p, numOfOutput:%p, buf:%p\n", dataOutput, numOfOutput, buf);
|
||||||
|
if (p->otype == 6) {
|
||||||
|
*(float *)dataOutput = (float)(p->sum / p->num);
|
||||||
|
} else if (p->otype == 7) {
|
||||||
|
*(double *)dataOutput = (double)(p->sum / p->num);
|
||||||
|
}
|
||||||
|
|
||||||
|
*numOfOutput=1;
|
||||||
|
|
||||||
|
printf("demo finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int demo_init(SUdfInit* buf) {
|
||||||
|
buf->ptr = calloc(1, sizeof(SDemo));
|
||||||
|
printf("demo init\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void demo_destroy(SUdfInit* buf) {
|
||||||
|
free(buf->ptr);
|
||||||
|
printf("demo destroy\n");
|
||||||
|
}
|
||||||
|
|
|
@ -10,12 +10,12 @@ typedef struct SUdfInit{
|
||||||
int const_item; /* 0 if result is independent of arguments */
|
int const_item; /* 0 if result is independent of arguments */
|
||||||
} SUdfInit;
|
} SUdfInit;
|
||||||
|
|
||||||
void sum_double(char* data, char type, int numOfRows, long long* ts, char* dataOutput, char* tsOutput,
|
void sum_double(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* tsOutput,
|
||||||
int* numOfOutput, SUdfInit* buf) {
|
int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
|
||||||
int i;
|
int i;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, type, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
|
printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
|
||||||
if (type == 4) {
|
if (itype == 4) {
|
||||||
r=*(int *)dataOutput;
|
r=*(int *)dataOutput;
|
||||||
for(i=0;i<numOfRows;++i) {
|
for(i=0;i<numOfRows;++i) {
|
||||||
r+=*((int *)data + i);
|
r+=*((int *)data + i);
|
||||||
|
@ -42,6 +42,23 @@ void sum_double_finalize(char* dataOutput, int* numOfOutput, SUdfInit* buf) {
|
||||||
printf("sum_double finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
|
printf("sum_double finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sum_double_merge(char* dataOutput, int* numOfOutput, SUdfInit* buf) {
|
||||||
|
int r = 0;
|
||||||
|
int sum = 0;
|
||||||
|
|
||||||
|
printf("sum_double_merge dataoutput:%p, numOfOutput:%p, buf:%p\n", dataOutput, numOfOutput, buf);
|
||||||
|
for (int i = 0; i < *numOfOutput; ++i) {
|
||||||
|
printf("sum_double_merge %d - %d\n", i, *((int*)dataOutput + i));
|
||||||
|
sum +=*((int*)dataOutput + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
*(int*)dataOutput=sum;
|
||||||
|
*numOfOutput=1;
|
||||||
|
|
||||||
|
printf("sum_double sum_double_merge, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int sum_double_init(SUdfInit* buf) {
|
int sum_double_init(SUdfInit* buf) {
|
||||||
buf->maybe_null=1;
|
buf->maybe_null=1;
|
||||||
buf->ptr = malloc(sizeof(int));
|
buf->ptr = malloc(sizeof(int));
|
||||||
|
|
Loading…
Reference in New Issue