Hate: In love with C

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: Hate: In love with C

Post by appleide »

Looks like it works exactly the same as C code that binds lua code to it. Programs the lua via stack. That should be fun. :)
I was thinking about doing pure computational stuff, e.g like recursively traversing a tree and calculate some value for each node based on its parent's value. Seems like it wouldn't be as 'easy' as I thought but I'm hoping it'll be faster to do this in lua.

This'll be cool. :)
User avatar
sauer2
Citizen
Posts: 61
Joined: Tue Sep 02, 2008 4:15 pm

Re: Hate: In love with C

Post by sauer2 »

You're trying to make löve hybrid Lua and C?
:D That would be cool, if this works!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Hate: In love with C

Post by Robin »

sauer2 wrote:You're trying to make löve hybrid Lua and C?
Very cool indeed, however, I feel the proper term would be "hÿbrid".
Help us help you: attach a .love.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Hate: In love with C

Post by rude »

You mean of course: CÖPULATION. :joker:

But do not expect the full C standard library, as it might look like we're going to have to export functions one by one into the TCC context. In particular, I can see how we might not want FILE, fwrite and all that. Generally, allowing C code is a security risk, but screw that. Awesomeness always takes priority over security. Also, files can't #include another files unless we make our own "fake" preprocessor. Which I suppose is doable.
User avatar
sauer2
Citizen
Posts: 61
Joined: Tue Sep 02, 2008 4:15 pm

Re: Hate: In love with C

Post by sauer2 »

Since C is rather not proper the same depending on compiler and platform and generation (e.g: sometimes stdio.h and sometimes stdlib.h), i don't think this matters, if there is a good documentation. ;)
User avatar
Star Crunch
Prole
Posts: 33
Joined: Sun Feb 15, 2009 12:13 am
Location: Monterrey, MX
Contact:

Re: Hate: In love with C

Post by Star Crunch »

Depending on what you want to do, this may also be worth a look:

http://luaforge.net/projects/alien/
Chris016
Prole
Posts: 22
Joined: Sat Aug 16, 2008 1:58 am

Re: Hate: In love with C

Post by Chris016 »

Another idea if you wanted to you could try something with Large C.
http://ubuntuforums.org/showthread.php?t=351973

That explains how you can do it. Ive tried it im sure it only works in linux. Its pretty cool you could program your own C macros too.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Hate: In love with C

Post by rude »

This now actually works in the internal LÖVE build. :ultrahappy:

Code: Select all

-- main.lua
love.native.compile("leet.c")
love.native.relocate()
leet = love.native.getSymbol("leet")
print(leet()) -- 1337

Code: Select all

// leet.c
#define lua_State void

int leet(lua_State * L)
{
	lua_pushinteger(L, 1337);
	return 1;
}
However:

1. I'm not sure whether this "much" functionality is actually needed. We demand that only modules be used, and not expose getSymbol:

Code: Select all

-- main.lua
love.native.compile("leet.c") -- Compiled and relocated.
require("leet")
print(leet.test()) -- 1337

Code: Select all

// leet.c
int test(lua_State * L) {
	lua_pushinteger(L, 1337);
	return 1;
}

static const lua_Reg leet_lib [] {
	{ "test" , test },
	{0,0}
}

int luaopen_leet(lua_State * L) {
	return luaL_register(L, "leet", leet_lib);
}
2. Not sure whether to allow multiple compilation contexts, and if yes, how?

Code: Select all

-- One choice
c = love.native.newCompiler()
c:compile( files )

Code: Select all

-- Another choice
love.native.compile(file1, file2, ... fileN) -- One context. Relocated automatically.
love.native.compile(file1, file2, ... fileN) -- Another context. Relocated automatically.
I think the former is impossible due to garbage collection. There's no (acceptable) way of knowing when there are no more references to relevant functions in Lua. Our options are then either a) never deallocate, or b) give developers access to free the compilers manually. I frown upon a), but not nearly as much as I frown upon b).

Any thoughts?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Hate: In love with C

Post by bartbes »

1 = good
2, take the second, I love these fast developments :P

btw, master thesis came out nice?
User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Hate: In love with C

Post by osgeld »

i am so lost
Post Reply

Who is online

Users browsing this forum: No registered users and 241 guests