Is there a global scope for storing Lua variables in civetweb?

已查看 18 次
跳至第一个未读帖子

Tamer Temizer

未读,
2018年4月26日 06:34:132018/4/26
收件人 civetweb
I want to be able to store some global variables that will be shared across different pages. Is there a global Lua scope that I can use or do I need to store it in some kind of a file? I didn't embed civetweb, it is running from document root.

bel

未读,
2018年4月27日 16:59:582018/4/27
收件人 civetweb
There are different ways to do this.

-) You could store values in a database (see test/page.lua)

-) You could use websockets sharing a common state (see test/websocket.lua)

-) If you have some const data to share between states, you could use a preload file (see docs/UserManual.md)

-) Indeed, you could do it manually and "store it in some kind of file", but depending on the use case, there are easier / better options

-) You could use a library to share the data

What data do you want to store?
Data type?
Read/write?

bel

未读,
2018年5月1日 16:30:272018/5/1
收件人 civetweb
In the current version (1.11 - not yet released), I added a small library I once created to exchange strings, numbers and boolean values between different Lua states. You can use it to share some read/write variables across different states.
See "test/page_shared.lua" as example how to use it.

If you need "read only" variables, I recommend to use a lua_preload_file.
回复全部
回复作者
转发
0 个新帖子