Page 1 of 1
Require a C file in Lua?
Posted: Sun Sep 15, 2013 12:11 am
by Eamonn
So, I'm experimenting with some things, and if it works out it should be pretty awesome, but I'm having trouble.
I'd need to require a C file, and a C header file of course, but I cannot seem to find a way to do this in Lua. I know there is a way to write C with Lua, but I can't find anything on that either.
So, is it possible to require a C file with Lua? Require didn't work for me, and neither did dofile.
There might be a really obvious answer that I can't find
Thanks!
Re: Require a C file in Lua?
Posted: Sun Sep 15, 2013 1:22 am
by davisdude
You could do io.open ( or love.filesystem. whatever...) along with
this. It's worth a try, at the least.
Re: Require a C file in Lua?
Posted: Sun Sep 15, 2013 1:59 am
by NightKawata
davisdude just what the fuck
but anyways...
LuaJIT's
FFI Library?
That's about as good as C with Lua gets. (At least, if you're doing what I think you are)
Re: Require a C file in Lua?
Posted: Sun Sep 15, 2013 2:37 am
by davisdude
NightKawata wrote:davisdude just what the fuck
but anyways...
What do you mean? I don't see what's wrong with it...
Re: Require a C file in Lua?
Posted: Sun Sep 15, 2013 4:12 am
by raidho36
I beleive by "require" eamonn means "load the executable code".
SHORT ANSWER: You don't.
Long answer: You need to compile the file first to a dymanically linked library, which would be .dll for Windows and .so for *nix, and then you can include it, and you would not need a header for it. Writing workable C code more complex than Hello World is already pretty hard, yet making a requireable library ain't that simple: to be requireable, library must have C Lua functions (for the lack of better term), that is callable Lua functions written in C which you hook up to the Lua. So it must strictly follow that big hardly documented "Using Lua In C" thing, which is an instant warranty of having to deal with really complicated matters. And, when you compile it, you must only include Lua headers but not link the Lua binaries to it, otherwise real Lua will fail to require this compiled library.
You really better off with LuaJIT, even though it's bad. If you want C code that bad, just write your entire app in C, and use liballeg as a framework instead of LÖVE.
Re: Require a C file in Lua?
Posted: Sun Sep 15, 2013 11:21 am
by Roland_Yonaba
Or
Alien. Yet, it needs dynamic libs too.
Note:
Totally unrelated, yet you might find some interest in it.