flat assembler
Message board for the users of flat assembler.
Index
> Windows > .:: FASm & LUA ::. |
Author |
|
vadana 12 Apr 2004, 12:46
Who tried dynamically to connect to LUA libriary.
|
|||
12 Apr 2004, 12:46 |
|
guignol 11 Mar 2019, 10:33
Who's LUA?
|
|||
11 Mar 2019, 10:33 |
|
sleepsleep 11 Mar 2019, 16:58
hi vadana,
https://debian-administration.org/article/264/Embedding_a_scripting_language_inside_your_C/C_code http://luabinaries.sourceforge.net/download.html the keyword for google would be "embed LUA in C application" |
|||
11 Mar 2019, 16:58 |
|
Ali.Z 13 Mar 2019, 17:05
mixing bytecode with assembly? seriously i see it as a bad thing. (but why mixing?)
_________________ Asm For Wise Humans |
|||
13 Mar 2019, 17:05 |
|
pelaillo 15 Apr 2019, 00:09
I would have preferred to see this post evolving. Lua and assembly are a match made in heaven.
Both at opposite sides of the programming spectrum but they can play along very well. The fact that lua is designed to be easily interfaced with C means that we will get a lot more power from assembly. Lua is a really well crafted piece of software and it will give you many things for free for your own application. Here's a teaser: a functionally equivalent fasm version of the example found at http://lua-users.org/wiki/SimpleLuaApiExample You would only need the lua53.dll library from https://www.lua.org/download.html Code: format PE CONSOLE entry start include 'win32a.inc' LUA_MULTRET = -1 section '.text' code readable executable start: invoke GetModuleHandle,0 mov [hInstance],eax invoke GetStdHandle,STD_OUTPUT_HANDLE mov [hStdout],eax ; Get a new lua context: lua allocates the memory and return a ponter in eax ; This context is the state for the lua thread in execution. We don't need to ; mess with it. Simply pass it as the first argument to any lua function. invoke luaL_newstate ; Store lua state for later reference (api functions don't change esi) mov esi,eax ; Load lua standard libraries into the context invoke luaL_openlibs,esi ; Load the script file invoke luaL_loadfilex,esi,script_name,NULL cmp eax,0 je .script_loaded invoke lua_tolstring,esi,-1,0 invoke wsprintf,buffer,script_error,eax invoke WriteFile,[hStdout],buffer,eax,io_bytes,NULL mov eax,1 jmp exit .script_loaded: invoke lua_createtable,esi,0,0 mov edi,1 .start_loop: push 0 edi fild qword [esp] fstp qword [esp] invoke lua_pushnumber,esi mov eax,edi add eax,edi push 0 eax fild qword [esp] fstp qword [esp] invoke lua_pushnumber,esi invoke lua_rawset,esi,-3 inc edi cmp edi,5 jle .start_loop invoke lua_setglobal,esi,table_name ; Run the script into the context invoke lua_pcallk,esi,0,LUA_MULTRET,0,0,0 cmp eax,0 je .show_result invoke lua_tolstring,esi,-1,io_bytes invoke wsprintf,buffer,run_error,eax invoke WriteFile,[hStdout],buffer,eax,io_bytes,NULL mov eax,1 jmp exit .show_result: invoke lua_tonumberx,esi,-1,0 fist dword [esp] invoke wsprintf,buffer,return_message invoke WriteFile,[hStdout],buffer,eax,io_bytes,NULL invoke lua_settop,esi,-2 invoke lua_close,esi mov eax,0 exit: invoke ExitProcess,eax section '.bss' readable writeable hInstance dd ? ; instance handle hStdout dd ? ; standard output handle io_bytes dd ? ; total bytes written buffer rb 256 section '.data' readable script_name TCHAR 'script.lua',0 script_error TCHAR "Couldn't load file: %s",13,10,0 run_error TCHAR "Failed to run script: %s",13,10,0 return_message TCHAR "Script returned %i",13,10,0 program_name TCHAR 'lua test',0 table_name TCHAR 'foo',0 section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ lua53,'LUA53.DLL',\ user,'USER32.DLL' import kernel,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess',\ GetStdHandle,'GetStdHandle',\ WriteFile,'WriteFile' import lua53,\ luaL_error,'luaL_error',\ luaL_loadfilex,'luaL_loadfilex',\ luaL_newstate,'luaL_newstate',\ luaL_openlibs,'luaL_openlibs',\ lua_close,'lua_close',\ lua_createtable,'lua_createtable',\ lua_pcallk,'lua_pcallk',\ lua_pushnumber,'lua_pushnumber',\ lua_rawset,'lua_rawset',\ lua_setglobal,'lua_setglobal',\ lua_settop,'lua_settop',\ lua_tolstring,'lua_tolstring',\ lua_tonumberx,'lua_tonumberx' import user,\ wsprintf,'wsprintfA' |
|||
15 Apr 2019, 00:09 |
|
sleepsleep 15 Apr 2019, 18:07
http://www.lua.org/manual/5.3/luac.html
luac output to .out, perhaps .dll in Windows, this make us more powerful. |
|||
15 Apr 2019, 18:07 |
|
Furs 17 Apr 2019, 11:51
I dislike Lua's bytecode, it's bloated as hell.
|
|||
17 Apr 2019, 11:51 |
|
rugxulo 18 Apr 2019, 05:31
I'm no Lua coder, but IIRC, the bytecode output is optional. By that I mean that the main "lua" can be built without the compiler frontend and only include the interpreter. So you can have separate bytecode (and separate "luac"), but I suppose it's rarely recommended.
BTW, the Lua book is heavily revamped in its fourth edition (5.3), but the older first edition (5.0) is available for free online. I do recommend checking that out. |
|||
18 Apr 2019, 05:31 |
|
pelaillo 22 Apr 2019, 21:20
Furs wrote: I dislike Lua's bytecode, it's bloated as hell. You don't need to mess with lua bytecode. Everything is handled by the shared library. Just keep the two realms separated (assembly and lua scripts). Lua is several times faster than any other general purpose interpreted language, specially for data related tasks. An assembly application could use Lua in the same way that Redis use it, for example. But there is no need to statically link it. Just call the shared library functions. |
|||
22 Apr 2019, 21:20 |
|
pelaillo 22 Apr 2019, 21:27
rugxulo wrote: I'm no Lua coder, but IIRC, the bytecode output is optional. By that I mean that the main "lua" can be built without the compiler frontend and only include the interpreter. You are right. The shared library contains the "engine", designed to be embedded by default. It is small, thread safe, and the full language is at your disposition. You can create the variables in assembly, apply a lua script over them and then process the result back in assembly. Or make functions in assembly to be called by any lua script. It is truly versatile and powerful. |
|||
22 Apr 2019, 21:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.