how to execute a c function which is written in informix? - informix

I have written a C function which print hello world
and registered as below:
CREATE FUNCTION my_func()
RETURNING INT
EXTERNAL NAME "/tmp/mytest.c"
LANGUAGE C
END FUNCTION;
placed the c code in /tmp/mytest.c in Informix server and the above function created. But when I am executing the function in dbeaver I am getting below error.
SQL Error[IX000]:User Defined Routine (my_func) module load failed
I have a Informix function which should call C function

Related

Lua 5.4 Calling a function declared as a string

I would need to call a function that is declared as a string
i.e local abc = "function x() print('math.sqrt(25)') end"
i've tried load(abc) that gives me no errors but nothing is printed and print(load(abc)) that returns function: 0000000000ebcea0
I've made another tries but nothing seems to suit my case (or probably i'm just bad)
Please read the manual...
If there are no syntactic errors, load returns the compiled chunk as a
function
If you want that function to be called, call it.
local abc = "function x() print('math.sqrt(25)') end"
local loadedFunction = load(abc)
loadedFunction()
or simply
load(abc)()
Of course you should check wether load actually succeeded.
If you want something to happen you probably should also call the function that has been defined by the function you loaded.
load(abc)()
x()

PostgreSQL error: function returning record called in context that cannot accept type record, on remote dblink call

When I run this code:
do
$func$
declare cmd text;
begin
cmd = FORMAT($$ select public.func_doit('%s'::date, '%s'::date); $$,'2019-01-01', '2019-03-01');
PERFORM DBLINK('my_conn', cmd);
end;
$func$
I receive the following error:
SQL Error [0A000]: ERROR: function returning record called in context that cannot accept type record
Where: SQL statement "SELECT DBLINK('my_conn', cmd)"
PL/pgSQL function inline_code_block line 12 at PERFORM
ERROR: function returning record called in context that cannot accept type record
Where: SQL statement "SELECT DBLINK('my_conn', cmd)"
PL/pgSQL function inline_code_block line 12 at PERFORM
ERROR: function returning record called in context that cannot accept type record
Where: SQL statement "SELECT DBLINK('my_conn', cmd)"
PL/pgSQL function inline_code_block line 12 at PERFORM
The function being called: public.func_doit, RETURNS void.
There is no record in the mix as referenced by the error message. The function just does something and there's nothing to return.
After placing notices inside the called function, non are posted, which means that the function doesn't even begin to execute.
I know the function works because when I call it directly from its local DB, it works as expected, with the same parameters.
PERFORM is the right statement to use here because the function doesn't return anything.
And I also tried: ...perform * from public.func_doit..., which throws a syntax error.
What could I be missing here?

Executing a function for dissection in a Lua Wireshark dissector?

I have a Lua Wireshark dissector that is structured like so:
-- Initialize Protocol
-- Initialize Protocol Fields
-- Register Protocol Fields
-- DissectionFunction(tvbuf, pktinfo, root)
-- Initialize Protocol
-- Function definitions.
I have a function written that I'd like to use to calculate some values, and then use those values in the dissector. So I wrote my function outside the dissection function and in the function definitions section.
But the function call also works within the dissector function, if called outside the dissector function Wireshark does not recognize it. Calling it in the dissection function is very inefficient, as it only needs to be executed once and will be executed for every frame instead.
Is there a way to call it once outside the dissection function?
I'm not quite sure of what the question is, but you can do the following in Lua
local function calculate_constant_value()
return a * b + c
end
local my_constant_value = calculate_constant_value()
function proto.dissector()
-- use my_constant_value here
end

How to show correct function names in error messages?

Let's say that I call some functions indirectly, via a variable. For example:
obj = {
on_init = function()
print "hello."
end,
on_destroy = function()
print "bye."
end,
on_do_something = function()
print "doing something."
error("Hi de hi, hi de ho!")
end,
}
local event = "do_something"
local func = obj["on_" .. event]
func()
All works fine.
However, the problem is that when the called function raises an exception (as in the code above) the error message isn't quite clear. It is thus:
lua: test.lua:13: Hi de hi, hi de ho!
stack traceback:
[C]: in function 'error'
test.lua:13: in function 'func'
test.lua:20: in main chunk
It says "in function 'func'". I'd prefer it to say "in function 'on_do_something'" instead.
I'd imagine this scenario to be very common. Is there a solution for this?
I tried calling the function thus:
obj["on_" .. event]()
But then the error message says "in function '?'", which isn't helpful either.
(I tried this code on Lua 5.1, 5.2 and LuaJIT without notable differences.)
This is a limitation of the heuristics used by Lua to provide names for functions.
In Lua, all functions are anonymous. A given function can be the value of several variables: global, local, and table fields. The Lua debug system, which is used in error handling, tries to find a reasonable name for a value based on where it came from by looking into the bytecode being executed.
See
Why is 'name' nil for debug.getinfo(1).
You have a few options. The debug module will try to produce something useful. For instance, you might be able to get the file name and line number where it was defined, if this is your own code. See
http://www.lua.org/pil/23.1.html for the list of what is available via debug module. Or, you might be able to define the functions in the module, then add them to the table:
-- module something
function a()
...
end
tt = {
fn1 = a,
...
}
Depending on where you trap the error (error handler installed via debug hook?), you could check if filename is the module where your table of functions is defined, and if it is, then use the debug module to print appropriate info based on your table structure etc; if it is not, just print the default traceback etc.

how to get caller of function within a function in lua?

how can one get the caller of function within a function in lua?
Specifically I'm looking (for debug purposes in the command output, e.g. print) the ability to log when a common function is called, with an indication of where it was called from.
This could be just the filename of where it was called from for example
i.e.
File 1 - Has commonly used function
File 2 - Calls of the the file one functions
PS Mud - I actually get a nil when doing this - is this normal then? No way to get more info in this case:
Called file;
SceneBase = {}
function SceneBase:new(options)
end
return SceneBase
Calling file:
require("views.scenes.scene_base")
local scene = SceneBase.new()
debug.getinfo(2).name will give you the name of the calling function if it has one and it is a string. If it's an anonymous function, you'll get nil, if it's stored in a table using something other than a string key, you'll get ?.
function foo() print(debug.getinfo(2).name) end
-- _G["foo"] => function name is a string
function bar() foo() end
bar() --> 'bar'
-- _G[123] => function name is a number
_G[123] = function() foo() end
_G[123]() --> '?'
-- function has no name
(function() foo() end)() --> 'nil'
The Lua debug library lets you get the stack trace.

Resources