Forum

> > CS2D > Scripts > Compile a Lua into DLL
Forums overviewCS2D overview Scripts overviewLog in to reply

English Compile a Lua into DLL

7 replies
To the start Previous 1 Next To the start

old Re: Compile a Lua into DLL

TimeQuesT
User Off Offline

Quote
In addition to user Starkkz

You have to rewrite your lua code into c or cpp or any other language that compilers allow dll compilation.

Then you have to make a lua file that includes / binds your dll to cs2d and executes a specific "main function" inside your dll.

old Re: Compile a Lua into DLL

MikuAuahDark
User Off Offline

Quote
1. Create new .h file and a single const char* variable, it will contains your lua script. You need to use hex dump(i don't know if it works for script larger than 4kb)
const char* mycode={...};


2. Now the .c file
1
2
3
4
5
6
7
#include"header.h"	// created header at above
#include<lua.h>
#include<lauxlib.h>

int __declspec(dllexport) luaopen_example(lua_State* L) {
	luaL_dostring(L,mycode);
}

3. In your script, load it like this
require("example")

or
assert(package.loadlib("exampledll.dll","luaopen_example"))()

Note: Method 2 is prefered if you don't want to change the package.cpath variable
Note2: CS2D Uses lua 5.1.4, so pick correct source code.

old Re: Compile a Lua into DLL

VaiN
User Off Offline

Quote
I'm curious, what would be the point in this as it relates to CS2D? Is it just to improve performance of Lua scripts or are you adding additional functionality somehow?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview