example_client.nim wraps the BWAPI client interface using pure Nim.
example_module.nim wraps the BWAPI module dll interface. Some C++ code is necessary to implement the AIModule interface, and Nim callbacks may be passed, as function pointers with the cdecl pragma, into the C++ implementation.
To support the above, I manually wrapped a few BWAPI dependencies.
It would be more efficient to automatically generate wrappers. There are 2 approaches: using/enhancing the existing c2nim, or building my own wrapper generator.
I installed c2nim using nimble: nimble install c2nim
Then I ran c2nim on the BWAPI header:
c2nim --cpp --header bwapi\include\BWAPI.h -o:BWAPI.nim
I had to modify Sublime's build command for 32-bit mode:
{
"shell_cmd": "\"c:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\vc\\vcvarsall.bat\" x86 && nim cpp --cpu:i386 $file_base_name"
}
compile on the command line with nim cpp main.nim
32-bit Nim is needed to compile 32-bit programs.
Started working on this, but it's incomplete.
Given C++ code Broodwar->isInGame()
, where it is a combination of the dereference operator on GameWrapper and method call Game.isInGame(), I couldn't get it to work as two separate wrapper methods. I needed to trick the compiler by making a single wrapper method GameWrapper.isInGame() which emits the ->
operator using the importcpp
pragma.
Nim does this, given the passL config setting:
cl.exe ${passL} ${libs} /nologo /DEBUG /Zi /F33554432 /Fe${output} ${objs}
The linker options must appear after the output filename, and have /link
prepended. This is how it should work:
cl.exe ${libs} /nologo /DEBUG /Zi /F33554432 /Fe${output} /link ${passL} ${objs}
client\bulletimpl.h(19, 41) Error: ';' expected
client\forceimpl.h(15, 41) Error: ';' expected
client\gameimpl.h(81, 57) Error: ';' expected
client\playerimpl.h(22, 41) Error: ';' expected
client\regionimpl.h(20, 39) Error: ';' expected
client\unitimpl.h(30, 51) Error: ';' expected
color.h(219, 61) Error: ')' expected
bestfilter.h(16, 41) Error: '> [end of template]' expected
filters.h(22, 45) Error: '> [end of template]' expected
position.h(11, 38) Error: '> [end of template]' expected
unaryfilter.h(22, 72) Error: '> [end of template]' expected
comparisonfilter.h(13, 50) Error: did not expect [
game.h(52, 48) Error: '[integer literal]' expected
Type.h(40, 33) Error: ')' expected
Interface.h(30, 15) Error: identifier expected, but found '= (pxAsgn)'
SetContainer.h(25, 61) Error: '[integer literal]' expected
Position.h(15, 36) Error: ';' expected
InterfaceEvent.h(37, 49) Error: '> [end of template]' expected