Przeglądaj źródła

[Minor] Fix lua_tensor usage

pull/4857/head
Vsevolod Stakhov 3 miesięcy temu
rodzic
commit
dd284d1c1e
No account linked to committer's email address
2 zmienionych plików z 9 dodań i 11 usunięć
  1. 6
    6
      src/lua/lua_tensor.c
  2. 3
    5
      src/lua/lua_tensor.h

+ 6
- 6
src/lua/lua_tensor.c Wyświetl plik

/*-
* Copyright 2020 Vsevolod Stakhov
/*
* Copyright 2024 Vsevolod Stakhov
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
res->size = -(res->size); res->size = -(res->size);
} }


rspamd_lua_setclass(L, TENSOR_CLASS, -1);
rspamd_lua_setclass(L, rspamd_tensor_classname, -1);


return res; return res;
} }
void luaopen_tensor(lua_State *L) void luaopen_tensor(lua_State *L)
{ {
/* Metatables */ /* Metatables */
rspamd_lua_new_class(L, TENSOR_CLASS, rspamd_tensor_m);
rspamd_lua_new_class(L, rspamd_tensor_classname, rspamd_tensor_m);
lua_pop(L, 1); /* No need in metatable... */ lua_pop(L, 1); /* No need in metatable... */
rspamd_lua_add_preload(L, "rspamd_tensor", lua_load_tensor); rspamd_lua_add_preload(L, "rspamd_tensor", lua_load_tensor);
lua_settop(L, 0); lua_settop(L, 0);
struct rspamd_lua_tensor * struct rspamd_lua_tensor *
lua_check_tensor(lua_State *L, int pos) lua_check_tensor(lua_State *L, int pos)
{ {
void *ud = rspamd_lua_check_udata(L, pos, TENSOR_CLASS);
void *ud = rspamd_lua_check_udata(L, pos, rspamd_tensor_classname);
luaL_argcheck(L, ud != NULL, pos, "'tensor' expected"); luaL_argcheck(L, ud != NULL, pos, "'tensor' expected");
return ud ? ((struct rspamd_lua_tensor *) ud) : NULL; return ud ? ((struct rspamd_lua_tensor *) ud) : NULL;
} }

+ 3
- 5
src/lua/lua_tensor.h Wyświetl plik

/*-
* Copyright 2020 Vsevolod Stakhov
/*
* Copyright 2024 Vsevolod Stakhov
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
#ifndef RSPAMD_LUA_TENSOR_H #ifndef RSPAMD_LUA_TENSOR_H
#define RSPAMD_LUA_TENSOR_H #define RSPAMD_LUA_TENSOR_H


#define TENSOR_CLASS "rspamd{tensor}"

typedef float rspamd_tensor_num_t; typedef float rspamd_tensor_num_t;


struct rspamd_lua_tensor { struct rspamd_lua_tensor {

Ładowanie…
Anuluj
Zapisz