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.8.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nimc-1.2.8.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.8.tar.gz
Algorithm Hash digest
SHA256 9f70f229fbab58f728f44b00b0b1c2c9d5c3cf8f80161dce3c81b8f6d4ebf106
MD5 e3ac7e4bbb95b56c6d28fd878a87b5a4
BLAKE2b-256 6401f29d94c7fea544380e35dd2216808c477b707ccb0fa43ebe03c97fffaaec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nimc-1.2.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ed0fdfeb97cf34ef27f9f84572a721d4fcbce9ab27c6f9b253faa2090e6c4fc2
MD5 5cb08ed9a2427a5103e14d216e625839
BLAKE2b-256 5027a9426ca31a4655ced2fcccb6daa19306964b75246237fe3bf099d8f51dbf

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