Python Package made by Mhadhbi Issam .
Project description
Nimc
command line utilty in order to create Defold naitive extensions in Nim .
♠ Install
pip install nimc
♠ Getting started
open terminal in root path of defold project :
♠♠ Create Extension named ext :
nimc init ext
♠♠ Build project :
nimc build ext
♠♠ Edit Nim code inside ext/extext.nim :
Note :
-
To export the functions from nim it must be add exported public through
*
annoation . -
To export the functions from nim it must be added with pargma through
{.cdecl,exportc,dynlib.}
annoation . -
After any of edit of nim file make sure to call build command
nimc build ext
-
the
nimc
will take care of cpp file to export functions !!
proc add*( a : cint , b:cint ): cint {.cdecl,exportc,dynlib.} =
return a + b
proc function*( a : cint , b:cint , c: cint ): cint {.cdecl,exportc,dynlib.} =
return a + b * 2
this will generate in cpp file :
static int nim_add(lua_State* L)
{
int a = luaL_checkinteger(L, 1);
int b = luaL_checkinteger(L, 2);
int result = add(
a ,
b ,
) ;
lua_pushinteger(L, result);
return 1;
}
static int nim_function(lua_State* L)
{
int a = luaL_checkinteger(L, 1);
int b = luaL_checkinteger(L, 2);
int c = luaL_checkinteger(L, 3);
int result = function(
a ,
b ,
c ,
) ;
lua_pushinteger(L, result);
return 1;
}
static const luaL_reg Module_methods[] =
{
{"add", nim_add},
{"function", nim_function},
{0, 0}
};
♠♠ Usage of naitive extension :
in any script file :
local result = ext.add(10,12)
print(result)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nimc-1.2.9.tar.gz
.
File metadata
- Download URL: nimc-1.2.9.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bf9c03ceb1de256655bb1cbf6e53678713ea5eb212412d5c3dbc3a3a3565408 |
|
MD5 | 92d006184fdaefa0723fc975be879762 |
|
BLAKE2b-256 | 8bc483fc8a5731e2357474d57a28d73406f2fb3af3cf08558b44024b2049c4ca |
File details
Details for the file nimc-1.2.9-py3-none-any.whl
.
File metadata
- Download URL: nimc-1.2.9-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ece8a1c1c09e497858b6db641665874a0aa2ecb06cfb4f5d022e4a7836f9d5d |
|
MD5 | ba6de2012c20be04bfc888573244117f |
|
BLAKE2b-256 | 960a02d87f54ca5b80647a20202fa8a4a007dde17e0f9563eae2577b014a304c |