[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C helloworld from inside Ravi
- From: Dibyendu Majumdar <mobile@...>
- Date: Tue, 20 Jun 2017 21:02:55 +0100
Hi Sean,
On 20 June 2017 at 01:13, Sean Conner <sean@conman.org> wrote:
> That's something my own C compiler module [1] does:
>
> local cc = require "org.conman.cc"
>
> local CODE = [[
> #include <stdio.h>
> #include <lua.h>
>
> int TestFunc(lua_State *L)
> {
> puts("hello world!\n");
> return 0;
> }
> ]]
>
> local f = cc.compile("TestFunc",CODE)
> f()
>
> -spc
>
How do you handle following code:
local testfunc = [[
struct lua_State;
extern int puts(const char *);
extern int TestFunc(void);
int TestFunc(void)
{
puts("hello world!\n");
return 0;
}
]]
I try to detect that the function has the expected prototype so that
above is rejected as below.
..\llvm64d\Debug\ravi: dmrc_test.lua:17: bad argument #1 to
'getfunction' (Invalid function: canot accept more than one argument
)
stack traceback:
[C]: in method 'getfunction'
dmrc_test.lua:17: in main chunk
[C]: in ?
Error message can be improved of course !
Anyway the issue with allowing users to write C code is basically that
it becomes very easy to crash the system. This is why I have not been
keen on providing automated FFI support in Ravi.
Regards
Dibyendu