Forum

> > CS2D > Scripts > Compile a Lua into DLL
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Compile a Lua into DLL

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Re: Compile a Lua into DLL

TimeQuesT
User Off Offline

Zitieren
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.

alt Re: Compile a Lua into DLL

MikuAuahDark
User Off Offline

Zitieren
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.

alt Re: Compile a Lua into DLL

VaiN
User Off Offline

Zitieren
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?
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht