Register | Login
Forum Index > Samples > Using Lua with Ziron
Author Message
Pages: 1
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1440] Using Lua with Ziron - posted: 2015-01-04 16:56:29
The latest release of Ziron 2.0.0.11 contains a lua include (experimental)

You will need to download the Lua DLL

Here is a quick example of loading a lua script:

Code:
program PE32_CUI 'test';

#include 'win_def.zir';
#include 'console.zir';

#include 'lua/lua.zir';

lua_state* L;

lua_loadlib('lua52-32.dll');
L = luaL_newstate();
luaL_openlibs(L); 

eax = luaL_loadfile(L, 'script.lua', nil);
if (eax != 0) {
  ecx = lua_tostring(L, -1);
  print('Couldn\'t load file: ',[char*]ecx,'\n');
} else {
  // Ask Lua to run our little script
  eax = lua_pcall(L, 0, LUA_MULTRET, 0);
  if (eax != 0) {
    ecx = lua_tostring(L, -1);
    print('Failed to run script: ',[char*]ecx,'\n');
  } else {
    lua_pop(L, 1);  // Take script return value out of the stack
  }
}

lua_close(L); 
lua_freelib();

wait_key();
ExitProcess(0);


A very super simple script:
Code:
--
-- Sample lua script for Ziron
--

print("Hello World!");

n = 1
while n <= 20000 do
  print("Hello, World "..n.."!");
  n = n + 1
end;


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1441] - posted: 2015-01-04 20:58:52
registering a function:

Code:
program PE32_CUI 'test';

#include 'win_def.zir';
#include 'console.zir';

#include 'lua/lua.zir';


function LUA_API printSomething(lua_State* L) {
  print('Hello World from Ziron Function!\r\n');
  
  // return the number of results
  return 0;
}

lua_state* L;

lua_loadlib('lua52-32.dll');
L = luaL_newstate();
luaL_openlibs(L);

/* register our functions */
lua_register(L, 'printSomething', @printSomething); 

eax = luaL_loadfile(L, 'script.lua', nil);
if (eax != 0) {
  ecx = lua_tostring(L, -1);
  print('Couldn\'t load file: ',[char*]ecx,'\n');
} else {
  // Ask Lua to run our little script
  eax = lua_pcall(L, 0, LUA_MULTRET, 0);
  if (eax != 0) {
    ecx = lua_tostring(L, -1);
    print('Failed to run script: ',[char*]ecx,'\n');
  } else {
    lua_pop(L, 1);  // Take script return value out of the stack
  }
}

lua_close(L); 
lua_freelib();

wait_key();
ExitProcess(0);


then your lua script can append:
Code:
-- call Ziron Function
printSomething();


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd