Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nimc-1.2.7.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

nimc-1.2.7-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file nimc-1.2.7.tar.gz.

File metadata

  • Download URL: nimc-1.2.7.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for nimc-1.2.7.tar.gz
Algorithm Hash digest
SHA256 e4e9e3f527baf7f32b23e1907aad12513c8c80257d89525609e3fb423e3d9672
MD5 baaba6c491940360b1e803391e4cf45d
BLAKE2b-256 03c28a8be53a7930bd0f4d33042a13d9527a391b3cdd7e7c7c0643914e0ba08d

See more details on using hashes here.

File details

Details for the file nimc-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: nimc-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for nimc-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 41168e393c99d05de440518a6bda84f6b9f685fbc0c5e8f33c84513c9d06c713
MD5 7c60b4449f00bc3220588738ae4a91de
BLAKE2b-256 169146e22eadb0267cbf465ded7dcf2466da6651b929cba2e5a72eacdd6c3273

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page