Require a C file in Lua?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Require a C file in Lua?

Post 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 :crazy:

Thanks!
"In those quiet moments, you come into my mind" - Liam Reilly
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Require a C file in Lua?

Post by davisdude »

You could do io.open ( or love.filesystem. whatever...) along with this. It's worth a try, at the least. :)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
NightKawata
Party member
Posts: 294
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: Require a C file in Lua?

Post 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)
"I view Python for game usage about the same as going fishing with a stick of dynamite. It will do the job but it's big, noisy, you'll probably get soaking wet and you've still got to get the damn fish out of the water." -taylor
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Require a C file in Lua?

Post by davisdude »

NightKawata wrote:davisdude just what the fuck
but anyways...
What do you mean? I don't see what's wrong with it...
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Require a C file in Lua?

Post 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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Require a C file in Lua?

Post by Roland_Yonaba »

Or Alien. Yet, it needs dynamic libs too.

Note: Totally unrelated, yet you might find some interest in it.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Iori Branford and 2 guests