Page 1 of 1

wiimote or arbitrary external library load

Posted: Tue Apr 14, 2009 3:11 am
by athanazio
Hey master of Love !

here comes an easy question, did you tought about the use of wiimote in LOVE ?

if NOT any ideas of how to load an aditional arbitrary ? there are some nice implementations of wiimote support
Im using a port of http://www.wiiuse.net/ to Java and works very well

peace and lots ot LOVE !!

Re: wiimote or arbitrary external library load

Posted: Tue Apr 14, 2009 3:58 am
by Xcmd
I'm not sure, but just off the top of my head I know that Love has a joystick implementation. As of this writing, you might be able to write a driver that registers the wiimote as a joystick instead of a mouse device. Then what you do is something along these lines:

If the wiimote is moving up and down, you simulate Analog Stick 1's Y axial tilt.
If the wiimote is moving left to right, you simulate Analog Stick 1's X axial tilt.

If you want to support tilting:
If the wiimote is tilting forward and back, you simulate Analog Stick 2's Y axial tilt.
If the wiimote is tilting left and right, you simulate Analog Stick 2's X axial tilt.

Then you register the nunchuck as a third analog stick. (Bear in mind Love allows you to check the number of analog sticks)

Then you have the various buttons report in as numbered buttons. A = 0, B = 1, Home = 2, Minus = 3, Plus = 4, Trigger = 5 etc.

That's just off the top of my head, though. I'm not the most knowledgeable resource on the subject. I could be very wrong but I'm speaking from the little bit of experience I have with joysticks and programming. Hope this at least helps point you in the right direction.

Re: wiimote or arbitrary external library load

Posted: Tue Apr 14, 2009 6:54 am
by bartbes
athanazio wrote:if NOT any ideas of how to load an aditional arbitrary ?
Put one binary module for every supported platform in the .love and use require to load them.

EDIT: Keep in mind you still need lua modules for this

Re: wiimote or arbitrary external library load

Posted: Tue Apr 14, 2009 11:21 am
by athanazio
so lets see if I understood,

if I build an dll of some C code with the name "bla.dll",
I just can use require() to load it ?

hummm not clear to me how it will make call to the functions in the dll,
does the require make the link, or the lua modules that you refer to make the link ?

thanks for the tip will research something about it.

*EDIT
from the programming in Lua 8.2 topic
The standard implementation offers this support for Windows (DLL), Linux, FreeBSD, Solaris, and some other Unix implementations. It should not be difficult to extend this facility to other platforms; check your distribution. (To check it, run print(loadlib()) from the Lua prompt and see the result. If it complains about bad arguments, then you have dynamic linking facility. Otherwise, the error message indicates that this facility is not supported or not installed.)
I tried to run print(loadlib()) but it says that is a nil function, is this available in the LOVE distribution ?

Re: wiimote or arbitrary external library load

Posted: Tue Apr 14, 2009 11:55 am
by bartbes
You've got yourself an old document, let me walk you through it.
Just as a hint why that didn't work, in 5.1 it's package.loadlib, but I'll let you use require.
  • Get yourself the official lua package
  • Use the interactive interpreter (WAY FASTER than using LÖVE everytime)
  1. Create yourself a dll/so (I'd suggest pure c/c++ so it's cross-platform)
  2. Export the function int luaopen_<libname>(lua_State *L) (replace <libname> with the libname, and yes, you need the lua headers and the lib)
  3. Export every function you want to use in lua to lua from within that luaopen function
  4. Every function should have the prototype: int (lua_State *L), these are exactly the same as you'd normally use with the lua API, check the reference manual for that
To export/expose functions to lua I'd suggest using luaL_register, saves you a lot of work.

Re: wiimote or arbitrary external library load

Posted: Wed Apr 15, 2009 2:34 am
by athanazio
Thanks ! thanks !! Thanks !!
http://digg.com/d12Wa7

now I will do my homework on this =) ;)