Skip to main content

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)

Metadata

Release files for nimc 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nimc 1.3.1
File Size Uploaded
nimc-1.3.1.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nimc 1.3.1
File Interpreter ABI Platform
nimc-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / nimc-1.3.1.tar.gz

Download URL nimc-1.3.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
151e08de65922c95ebf533bc4927049d6600b1f5a0251e336ed013595ad97f77
BLAKE2b-256 checksum
How to use checksums
c5fb4289af8f1bcfbcbf88e26f0534f3ec13674d274946e157e6a4cf3deb0237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / nimc-1.3.1-py3-none-any.whl

Download URL nimc-1.3.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c29d8ea19ceb343a39d7c7e85e61267745fc76faadff86ea036dc648b93535a
BLAKE2b-256 checksum
How to use checksums
744cf13f9765ead688a16f810401a2405644a497e8539d1cec5194c1a8b6391b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files

1.3.0

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page