FreeTrack Forum

Welcome, you're not connected. ( Log in - Register )

RSS >  Lua Interface for Freetrack
Lord_Nothing #1 30/08/2012 - 18h29

Class : Apprenti
Posts : 6
Registered on : 24/05/2008

Off line

k so i was adding freetrack support to my lua standalone game engine and i was able to talk to the dll with alien. so heres my code. a lot of games have lua scripting built in and so mods can be created to talk to freetrack in cases where the game source is unavailable. this would allow you to add freetrack support to such games.


--use alien to import functions
require("alien")

--handle dll name and pathing
local ftLibPath = "C:\Program Files (x86)\FreeTrack\"
local ftLibName = "FreeTrackClient"
local ftLibExt = "dll"

--get a handle on the dll
local ftLib = alien.load(ftLibPath..ftLibName.."."..ftLibExt)

--export functions
ftLib.FTGetData:types{ ret = "byte", "pointer" }
ftLib.FTGetDllVersion:types{ ret = "string" }
ftLib.FTReportName:types{ ret = "void", "int" }
ftLib.FTProvider:types{ ret = "string" }

--output struct
local FreeTrackData = alien.defstruct{
   {"dataID", "ulong"},
   {"camWidth", "long"},
   {"camHeight", "long"},
   {"yaw", "float"},
   {"pitch", "float"},
   {"roll", "float"},
   {"x", "float"},
   {"y", "float"},
   {"z", "float"},
   {"rawYaw", "float"},
   {"rawPitch", "float"},
   {"rawRoll", "float"},
   {"rawX", "float"},
   {"rawY", "float"},
   {"rawZ", "float"},
   {"x1", "float"},
   {"y1", "float"},
   {"x2", "float"},
   {"y2", "float"},
   {"x3", "float"},
   {"y3", "float"},
   {"x4", "float"},
   {"y4", "float"}
}

--create a structure
local ftData = FreeTrackData:new()
--loop forever
while true do
   --some strings
   print(ftLib.FTProvider())
   print(ftLib.FTGetDllVersion())
   --not sure what this does at all
   ftLib.FTReportName(453)
   --update the struct
   ftLib.FTGetData(ftData())
   --use values
   print(" Pitch: "..ftData.pitch)
   print(" Yaw:   "..ftData.yaw)
   print(" Roll:  "..ftData.roll)
   print(" X:     "..ftData.x)
   print(" Y:     "..ftData.y)
   print(" Z:     "..ftData.z)
   print("")
end


this is just preliminary so im not sure if im closing things down right or checking for errors enough. documentation on alien is hard to come by it seems.

this works by itself if you have lua for windows installed and will print the freetrack data to a console. it uses the alien module which comes with lfw or can be downloaded by itself or with lua rocks. all the games ive used external modules on usually require you to copy the library dlls to the program folder, but im sure that varies with lua implementations.

*edit*
changed ftLibPath to default install path. you can change this if you have your dll somewhere else.
Edited by Lord_Nothing on 31/08/2012 at 02h24.

 >  Fast reply

Message

 >  Stats

1 user(s) connected during the last 10 minutes (0 member(s) and 1 guest(s)).