1. Tile Engine Wrapper Help
- Posted by Icy_Viking Oct 06, 2022
- 532 views
Hello all,
I was using Greg's FFI library to try and wrap Tile Engine. So far the wrapper itself appears to run without error when running it through eui.exe However when I went to make a test example, I got the following error. I feel the error has something to do with dealing with an opaque struct.
ffi.e: 908 attempt to subscript an atom (reading from it) in assignment to 'fn'
Tile engine.h file TLNAPI TLN_Engine TLN_Init (int hres, int vres, int numlayers, int numsprites, int numanimations);
Wrapper code
include std/machine.e include std/math.e include std/ffi.e public constant TLN_SpriteState = define_c_type({ C_INT, --x --screen pos x C_INT, --y --screen pos y C_INT, --w --actual width of screen after scaling C_INT, --h --actual height of screen after scaling C_UINT, --flags --flags C_POINTER, --assigned palette C_POINTER, --spriteset C_INT, --index C_BOOL, --enabled C_BOOL --collision }) public constant TLN_Engine = define_c_type({ C_POINTER }) --The TLN_Engine is an opaque struct export constant te = open_dll("Tilengine.dll"), --defgroup setup --Basic setup and management xTLN_Init = define_c_func(te,"+TLN_Init",{C_INT,C_INT,C_INT,C_INT,C_INT},TLN_Engine), xTLN_Deinit = define_c_proc(te,"+TLN_Deinit",{}), $
Example
include tileengine.e procedure main() sequence foreground = {} TLN_Init(400,240,1,0,0) foreground = TLN_LoadTilemap("Sonic_md_fg1.tmx",0) TLN_SetLayerTilemap(0,foreground) TLN_CreateWindow("Example",0) while TLN_ProcessWindow() do TLN_DrawFrame(0) end while TLN_DeleteTilemap(foreground) TLN_Deinit() end procedure main()
Let me know if you need more code or the ex.err file. If anyone can help.
2. Re: Tile Engine Wrapper Help
- Posted by ghaberek (admin) Oct 07, 2022
- 480 views
Hello all,
I was using Greg's FFI library to try and wrap Tile Engine. So far the wrapper itself appears to run without error when running it through eui.exe However when I went to make a test example, I got the following error. I feel the error has something to do with dealing with an opaque struct.
ffi.e: 908 attempt to subscript an atom (reading from it) in assignment to 'fn'
Tile engine.h file TLNAPI TLN_Engine TLN_Init (int hres, int vres, int numlayers, int numsprites, int numanimations);
This is happening because the id returned from define_c_func() is -1, indicating the function name was not found. There's no check for this in c_func() so it fails the subscript to the first element of m_funcs which is 0.
I can add some error handling so it crashes better, but the question why did it not find the function? What binaries are you using?
-Greg
3. Re: Tile Engine Wrapper Help
- Posted by Icy_Viking Oct 07, 2022
- 479 views
Hello all,
I was using Greg's FFI library to try and wrap Tile Engine. So far the wrapper itself appears to run without error when running it through eui.exe However when I went to make a test example, I got the following error. I feel the error has something to do with dealing with an opaque struct.
ffi.e: 908 attempt to subscript an atom (reading from it) in assignment to 'fn'
Tile engine.h file TLNAPI TLN_Engine TLN_Init (int hres, int vres, int numlayers, int numsprites, int numanimations);
This is happening because the id returned from define_c_func() is -1, indicating the function name was not found. There's no check for this in c_func() so it fails the subscript to the first element of m_funcs which is 0.
I can add some error handling so it crashes better, but the question why did it not find the function? What binaries are you using?
-Greg
I figured it out. I had the DLL in the wrong place. It needed to be in the bin folder.