Skip to content

Commit b9862d7

Browse files
author
Miqueas
committed
Added multi-state example and minor changes in meson.build
1 parent bb7e53d commit b9862d7

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/12-multi-state.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
3+
#include <lua.h>
4+
#include <lualib.h>
5+
#include <lauxlib.h>
6+
7+
/* In this example we create an small library
8+
* and return it as a table
9+
*/
10+
11+
int main(void) {
12+
lua_State *L1 = luaL_newstate();
13+
lua_State *L2 = luaL_newstate();
14+
15+
luaL_openlibs(L1);
16+
luaL_openlibs(L2);
17+
18+
lua_getglobal(L1, "print");
19+
lua_getglobal(L2, "print");
20+
lua_pushstring(L1, "Hello from Lua State 1");
21+
lua_pushstring(L2, "Hello from Lua State 2");
22+
23+
lua_call(L1, 1, 0);
24+
lua_call(L2, 1, 0);
25+
26+
lua_close(L1);
27+
lua_close(L2);
28+
}

src/meson.build

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ configure_file(
1818
input: 'constants.h.in',
1919
output: 'constants.h',
2020
configuration: {
21-
'table': meson.project_source_root() / 'src' / '04-table.lua',
22-
'metatable': meson.project_source_root() / 'src' / '05-metatable.lua',
23-
'hooks': meson.project_source_root() / 'src' / '11-hooks.lua'
21+
'table': meson.current_source_dir() / '04-table.lua',
22+
'metatable': meson.current_source_dir() / '05-metatable.lua',
23+
'hooks': meson.current_source_dir() / '11-hooks.lua'
2424
}
2525
)
2626
# ==== Example 01: hello world ==== #
@@ -109,22 +109,26 @@ addfn_lua = configure_file(
109109
# ==== Example 11: hooks ==== #
110110
hooks_exe = executable('11-hooks', '11-hooks.c', dependencies: lua51_dep)
111111

112+
# ==== Example 12: multiple states ==== #
113+
multi_state_exe = executable('12-multi-state', '12-multi-state.c', dependencies: lua51_dep)
114+
112115
if tests
113116
test('01 hello world', hello_world_exe)
114117
# This example is expected to fail
115118
test('02 global function', lua51_bin, args: [ gfunc_lua ], should_fail: true)
116119
# Setting the 'LUA_CPATH' env prevents the test to fail. This is 'cuz Lua will not find the .so file otherwise if you
117120
# run `meson test` from other directory
118-
test('03 basic library', lua51_bin, args: [ basic_lib_lua ], env: { 'LUA_CPATH': meson.build_root() / 'src' / '?.so' })
121+
test('03 basic library', lua51_bin, args: [ basic_lib_lua ], env: { 'LUA_CPATH': meson.current_build_dir() / '?.so' })
119122
test('04 table', table_exe)
120123
test('05 metatable', metatable_exe)
121-
test('06 userdata', lua51_bin, args: [ userdata_lua ], env: { 'LUA_CPATH': meson.build_root() / 'src' / '?.so' })
124+
test('06 userdata', lua51_bin, args: [ userdata_lua ], env: { 'LUA_CPATH': meson.current_build_dir() / '?.so' })
122125
test('07 stack dump', stack_dump_exe)
123126
test('08 versions (5.1)', versions_51_exe)
124127
test('08 versions (5.2)', versions_52_exe)
125128
test('08 versions (5.3)', versions_53_exe)
126129
test('08 versions (5.4)', versions_54_exe)
127-
test('09 newlib (5.2+)', lua52_bin, args: [ newlib_lua ], env: { 'LUA_CPATH': meson.build_root() / 'src' / '?.so' })
128-
test('10 functions', lua51_bin, args: [ addfn_lua ], env: { 'LUA_CPATH': meson.build_root() / 'src' / '?.so' })
130+
test('09 newlib (5.2+)', lua52_bin, args: [ newlib_lua ], env: { 'LUA_CPATH': meson.current_build_dir() / '?.so' })
131+
test('10 functions', lua51_bin, args: [ addfn_lua ], env: { 'LUA_CPATH': meson.current_build_dir() / '?.so' })
129132
test('11 hooks', hooks_exe)
130-
endif
133+
test('12 multi state', multi_state_exe)
134+
endif

0 commit comments

Comments
 (0)